Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <cassert> #include <iostream> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <set> #include <map> #include <bitset> #include <functional> #include <numeric> using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<((x))<<endl #define fi first #define se second #define INF 2147483600 #define long long long int main(){ int p,q; cin>>p>>q; int g =
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } int P, Q; int main() { cin >> P >> Q; int v = Q / gcd(P, Q); for (int d = 2; d * d <= v; ++d) { while ((v / d) % d == 0) { v /= d; } } cout << max(2, v) << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; import java.util.ArrayList; public class Main { Scanner sc = new Scanner(System.in); public void run(){ int p = sc.nextInt(); int q = sc.nextInt(); calc(p, q); } public void calc(int p, int q){ int a = q; int b = p; int max = 0; while(true){ int c = a % b; if(c == 0){ max = b; break; } else{ a = b; b = c; } } q = q / max; int ans = -1; char[] memo = new char[100000]; for(int i = 2; i < Math.min(q, 100000); i++){ if(memo[i] == 0){ long k = i; while(true){ if(k > q || k >= 100000) break; else if(k == q) { ans = i; break; } else{ memo[(int)k] = 1; k = k * i; } } } if(ans != -1) break; } if(ans == -1) ans = q; System.out.println(ans); } public static void main(String[] args){ new Main().run(); } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; import java.util.ArrayList; public class Main { Scanner sc = new Scanner(System.in); public void run(){ int p = sc.nextInt(); int q = sc.nextInt(); calc(p, q); } public void calc(int p, int q){ int a = q; int b = p; int max = 0; while(true){ int c = a % b; if(c == 0){ max = b; break; } else{ a = b; b = c; } } q = q / max; int ans = -1; char[] memo = new char[100000]; for(int i = 2; i < Math.min(q, 100000); i++){ if(memo[i] == 0){ long k = i; while(true){ if(k == q) { ans = i; break; } else if(k > q) { break; } else{ if(k < 100000) memo[(int)k] = 1; k = k * i; } } } if(ans != -1) break; } if(ans == -1) ans = q; System.out.println(ans); } public static void main(String[] args){ new Main().run(); } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> using namespace std; int main() { int p, q, r; cin >> p >> q; for (size_t i = p + 1 - 1; i >= 1; i--) { if (!(p % i | q % i)) { r = i; break; } } cout << q / r << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
// ?????¬???????????¬?????? #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <functional> using namespace std; #define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++) #define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++) #define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--) #define int long long int template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} typedef pair<int, int> pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; constexpr ll INF = 1001001001001001LL; constexpr ll MOD = 1000000007LL; signed main() { int p, q; cin >> p >> q; int g = __gcd(p, q); p /= g, q /= g; if(p != 1) cout << q << endl; else { for(int i=2; i*i<=q; i++) { int x = q; while(x % i == 0) x /= i; if(x == 1) { cout << i << endl; return 0; } } cout << q << endl; } return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<iostream> #include<vector> using namespace std; int gcd(int a, int b){ if(b==0) return a; else return gcd(b, a%b); } int main(){ int p, q; cin>> p>> q; q=q/gcd(p, q); vector<int> v; for(int i=2; i*<=q; i++){ if(q%i==0){ v.push_back(i); while(q%i==0) q/=i; } } int r=1; for(int i=0; i<v.size(); i++) r*=v[i]; cout<< r<< endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<iostream> using namespace std: int main(){ int p, q; cin >> p >> q; cout << q/__gcd(p, q) << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18; const int inf = 1e9; const double eps = 1e-12; const double pi = acos(-1); template <typename T> istream& operator>>(istream& is, vector<T>& vec) { for (auto&& x : vec) is >> x; return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (long long i = (0), __last_i = (vec.size()); i < __last_i; i++) { if (i) os << " "; os << vec[i]; } return os; } template <typename T> ostream& operator<<(ostream& os, const vector<vector<T> >& vec) { for (long long i = (0), __last_i = (vec.size()); i < __last_i; i++) { if (i) os << endl; os << vec[i]; } return os; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(0); long long p, q; cin >> p >> q; cout << max(2LL, q / gcd(p, q)) << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { int p, q; cin >> p >> q; int d = gcd(p, q); cout << q / d << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int p, q; cin >> p >> q; q = q / gcd(p, q); vector<int> v; for (int i = 2; i * i <= q; i++) { if (q % i == 0) { v.push_back(i); while (q % i == 0) q /= i; } } int r = 1; for (int i = 0; i < v.size(); i++) r *= v[i]; cout << r << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
using System; using System.Linq; namespace _2706 { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = x[0]; int b = x[1]; while (a != 0) { int z = b % a; b = a; a = z; } Console.WriteLine(x[1] / b); } } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int p, q; vector<int> primes; const int MA = 30000000; bool t[MA * 2]; void eratosu() { t[1] = 1; for (int i = 2; i <= MA; i++) { if (t[i] == 0) { primes.push_back(i); for (int j = i * 2; j <= MA; j += i) t[j] = 1; } } } bool check(int x) { int a = x; int aa = x; while (aa <= q) { if (aa == q) return 1; aa = aa * a; } return 0; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { eratosu(); cin >> p >> q; int gc = gcd(p, q); int np = p, nq = q; p = np / gc; q = nq / gc; int ans = 1, qq = q; int cnt = 0; for (int i = 0; i < primes.size(); i++) { int now = primes[i]; if (q % now == 0) ans *= now, cnt++; while (q % now == 0) q /= now; } if (cnt == 0) ans *= q; cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100005; map<int, int> mp; int prime[MAX_N]; bool is_prime[MAX_N]; int sieve(int n) { int p = 0; for (int i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (int i = 2; i <= n; i++) { if (is_prime[i]) { prime[p++] = i; for (int j = 2 * i; j <= n; j += i) { is_prime[j] = false; } } } return p; } int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } int main() { int p, q; cin >> p >> q; q /= gcd(p, q); int mx = (int)(sqrt(q + 1)); sieve(mx); for (int i = 0; prime[i] != 0; i++) { int hoge = prime[i]; int bf = q; while (bf % hoge == 0 && bf != hoge) { bf /= hoge; } if (bf == hoge) { cout << bf << "\n"; return 0; } } cout << q << "\n"; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e9 + 10; const long long linf = (long long)1e18 + 10; const long long mod = (long long)(1e9 + 7); const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1}; const double eps = 1e-10; long long mop(long long a, long long b, long long m = mod) { long long r = 1; a %= m; for (; b; b >>= 1) { if (b & 1) r = r * a % m; a = a * a % m; } return r; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } bool ool(int x, int y, int h, int w) { return ((x < 0) || (h <= x) || (y < 0) || (w <= y)); } bool deq(double a, double b) { return abs(a - b) < eps; } struct oreno_initializer { oreno_initializer() { cin.tie(0); ios::sync_with_stdio(0); } } oreno_initializer; int p, q; signed main() { cin >> p >> q; if (q == 1) cout << 2 << '\n'; else { for (int i = q; i <= 1e9; i += q) if (i % p == 0) return cout << i / p << '\n', 0; } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX, MOD = 1e9 + 7; int gcd(int x, int y) { if (x < y) swap(x, y); if (!(x % y)) return y; else return gcd(y, x % y); } int main() { int p, q; cin >> p >> q; int div = gcd(p, q); cout << q / div << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } bool isPrime[100000]; int main() { int p, q; cin >> p >> q; int d = gcd(p, q); q /= d; fill(isPrime, isPrime + 100000, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i < 100000; i++) { if (!isPrime[i]) continue; for (int k = 2; i * k < 100000; k++) isPrime[k * i] = false; } int r = -1; vector<pair<int, int> > V; int temp = q; for (int i = 2; i <= q && i < 100000; i++) { if (!isPrime[i]) continue; if (temp % i == 0) { int cnt = 0; while (temp % i == 0) { cnt++; temp /= i; } if (r == -1) { r = cnt; } else { r = gcd(r, cnt); } V.emplace_back(i, cnt); } } if (r == -1 || r == 1) { cout << q << endl; return 0; } int ans = 1; for (auto v : V) { int k = v.first; for (int i = 0; i < v.second / r; i++) ans *= k; } cout << ans << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { int p, q; cin >> p >> q; int d = gcd(p, q); q /= d; for (long long i = 2; i * i < q; i++) { long long x = i * i; while (x < q) x *= i; if (x == q) { q = i; break; } } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const double EPS = (1e-10); using namespace std; using Int = long long; const Int MOD = 1000000007; void fast_input() { cin.tie(0); ios::sync_with_stdio(false); } template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } vector<pair<int, int>> prime_factorization(int n) { int k = n; vector<pair<int, int>> ret; for (int i = 2; i <= sqrt(n); i++) { int cnt = 0; while (k % i == 0) { k /= i; cnt++; } if (cnt) ret.push_back({i, cnt}); } if (k > 1) ret.push_back({k, 1}); return ret; } int main(void) { int p, q; cin >> p >> q; while (gcd(p, q) != 1) { int tmp = gcd(p, q); p /= tmp; q /= tmp; } vector<pair<int, int>> qfac = prime_factorization(q); int GCD = qfac[0].second; for (int i = 0; i < qfac.size(); i++) { GCD = gcd(GCD, qfac[i].second); } int ans = 1; for (int i = 0; i < qfac.size(); i++) { int lim = qfac[i].second / GCD; for (int j = 0; j < lim; j++) { ans *= qfac[i].first; } } cout << ans << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
# -*- coding: utf-8 -*- p, q = map(int, input().split()) ret = q for b in range(1, 100000): if b ** 1000 * p % q == 0: ret = min(ret, b) print(ret)
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const double EPS = (1e-10); using namespace std; using Int = long long; const Int MOD = 1000000007; void fast_input() { cin.tie(0); ios::sync_with_stdio(false); } template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } int main(void) { int p, q; cin >> p >> q; while (gcd(p, q) != 1) { int tmp = gcd(p, q); p /= tmp; q /= tmp; } cout << q << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<iostream> #include<algorithm> using namespace std; int main(){ int p, q; cin >> p >> q; cout << q/__gcd(p, q) << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
# -*- coding: utf-8 -*- import math p, q = map(int, input().split()) g = math.gcd(p, q) p, q = p // g, q // g; ret = q for b in range(1, 40000): if b ** 1000 * p % q == 0: ret = min(ret, b) print(ret)
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (x < y) swap(x, y); int z; while (y) { z = x % y; x = y; y = z; } return x; } int main() { int p, q; cin >> p >> q; cout << q / gcd(p, q) << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { long long int a, b; cin >> a >> b; long long int c = b / gcd(a, b); long long int ans = 1; long long int ma = c; for (long long int i = 2; i <= c; i++) { if (c % i == 0) { ans *= i; while (c % i == 0) c /= i; } } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; unsigned int p, q; vector<int> yakusuu; int main() { cin >> p >> q; for (int i = 1; i <= p / 2; i++) { if (p % i == 0) { yakusuu.push_back(i); } } yakusuu.push_back(p); for (int j = 0; j < yakusuu.size(); j++) { if (q % yakusuu[j] == 0) q = q / yakusuu[j]; } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(){ int p,q; cin>>p>>q; int a=__gcd(p,q); p/=a,q/=a; int ans=q; if(q%p==0) { int ans=2; while(q%ans)ans++; } cout <<ans<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: p,q = LI() g = fractions.gcd(p,q) t = q//g k = 1 while t % 4 == 0: k *= 2 t //= 4 for i in range(3,int(math.sqrt(t))+2,2): ii = i**2 while t % ii == 0: k *= i t //= ii rr.append(t*k) break return '\n'.join(map(str, rr)) print(main())
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <iostream> #include <cmath> using namespace std; int gcd(int a,int b){ if(a<b){swap(a,b);} if(!b){return a;} return gcd(b,a%b); } int main(){ int a=1,p,q,i,gc; vector<int> cds; cin>>p>>q; gc=gcd(p,q); p/=gc;q/=gc; for(i=2;i<sqrt(q)+1;i++){ if(!(q%i)){ a*=i; while(!(q%i)){q/=i;} } } a*=q; cout<<a<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int p, q; cin >> p >> q; int g = __gcd(p, q); int b = q / g; int ans = 1; rep(i, 1000006) if (i > 1) { if (b % i == 0) { ans *= i; while (b % i == 0) b /= i; } } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int p, q; cin >> p >> q; int x = 1, a = p, b = q; for (int i = 2; i <= p; ++i) { if (a % i == 0 && b % i == 0) while (a % i == 0 && b % i == 0) { x *= i; a /= i, b /= i; cout << x << ' ' << i << endl; } } cout << q / x << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int p, q, x; cin >> p >> q; if (p < q) swap(p, q); int a = p; while (1) { if (p % q != 0) { x = p % q; p = q; q = x; continue; } break; } cout << a / q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } queue<long long int> q; vector<bool> prime(1000000000 + 1, true); void make(long long int M) { prime[0] = prime[1] = false; long long int i; for (i = 2; i * i <= M + 1; i++) { if (prime[i]) { long long int j = 2; q.push(i); while (i * j < M + 1) { prime[i * j] = false; j++; } } } return; } int main() { long long int a, b; cin >> a >> b; long long int c = b / gcd(a, b); long long int ans = 1; long long int ma = c; for (int i = 2; i * i < ma; i++) { if (c % i == 0) { ans *= i; while (c % i == 0) c /= i; } } ans *= c; cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int p, q; cin >> p >> q; q /= gcd(p, q); for (int i = 2; i < 32000; i++) { long long int x = i; while (x <= q) { if (x == q) { cout << i << endl; return 0; } x *= i; } } cout << q << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; bool sosu(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } long long gcd(long long a, long long b) { while (b) b ^= a ^= b ^= a %= b; return a; } int main() { long long A, B, i = 2; cin >> A >> B; long long W = B / gcd(A, B); one:; for (int i = 2; i < sqrt(W); i++) { if (W == i * i) { W = i; goto one; } } cout << W << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i,n) for(i=0;i<n;i++) #define loop(i,a,n) for(i=a;i<n;i++) #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define int ll typedef vector<int> vi; typedef pair<int,int> pii; signed main(void) { int i,j; int p,q; cin>>p>>q; q=q/__gcd(p,q); ll ans=1; for(i=2;i*i<=q;i++)if(q%i==0){ ans*=i; while(q%i==0)q/=i; } cout<<ans<<endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { static PrintWriter out; static InputReader ir; static void solve() { int p = ir.nextInt(); if(p==0){ out.println(2); System.exit(0); } int q = ir.nextInt(); int a = q / gcd(p, q); boolean[] prime=sieveOfEratosthenes(a); int ret=1; for(int i=2;i<=Math.sqrt(a);i++){ if(!(a%i==0)) continue; if(prime[i]) ret*=i; if(prime[a/i]) ret*=a/i; } out.println(ret); } public static boolean[] sieveOfEratosthenes(int n) { boolean[] res = new boolean[n + 1]; Arrays.fill(res, true); res[0] = res[1] = false; for (int i = 2; i <= Math.sqrt(n); i++) { if (res[i]) { for (int j = i + i; j <= n; j += i) { res[j] = false; } } } return res; } public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) throws Exception { ir = new InputReader(System.in); out = new PrintWriter(System.out); solve(); out.flush(); } static class InputReader { private InputStream in; private byte[] buffer = new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) { this.in = in; this.curbuf = this.lenbuf = 0; } public boolean hasNextByte() { if (curbuf >= lenbuf) { curbuf = 0; try { lenbuf = in.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return false; } return true; } private int readByte() { if (hasNextByte()) return buffer[curbuf++]; else return -1; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private void skip() { while (hasNextByte() && isSpaceChar(buffer[curbuf])) curbuf++; } public boolean hasNext() { skip(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[][] nextCharMap(int n, int m) { char[][] map = new char[n][m]; for (int i = 0; i < n; i++) map[i] = next().toCharArray(); return map; } } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; long long gcd; long long c = max(a, b); long long d = min(a, b); while (true) { if (c % d == 0) { gcd = d; goto C; } else { c -= d; if (c <= d) { swap(c, d); } } } C: cout << b / gcd << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long c; while (a != 0) { c = a; a = b % a; b = c; } return b; } int main() { cin.tie(0); ios::sync_with_stdio(false); long long p, q; cin >> p >> q; long long g = gcd(p, q); long long res = q / g; if (res == 1) res = 10; cout << res << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using msi = map<string, int>; using mii = map<int, int>; using pii = pair<int, int>; using vlai = valarray<int>; using ll = long long; constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } constexpr int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { int p, q; cin >> p >> q; cout << q / gcd(p, q) << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; unsigned int p, q; vector<int> yakusuu; int main() { cin >> p >> q; for (int i = 1; i <= p / 2; i++) { if (p % i == 0) { yakusuu.push_back(i); } } for (int j = 0; j < yakusuu.size(); j++) { if (q % yakusuu[j] == 0) q = q / yakusuu[j]; } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAX_N=1e2; // 1e8=x, 1e7=? 1e6=o int n[MAX_N+1]={}; vector <int> prime; void eratos_sieve(){ for(int i=2;i<=MAX_N;i++){ if(!n[i]){ prime.push_back(i); for(int j=i;j<=MAX_N;j+=i) n[j]=1; } } } int main(){ eratos_sieve(); int p,q,r=1; cin>>p>>q; p=q/__gcd(p,q); for(int i=0;i<(int)prime.size();i++) if(!(p%prime[i])) r*=prime[i]; cout<<r<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long p, q; int main() { cin >> p >> q; for (long long i = 2; i <= 1000; i++) { if (p * i % q == 0) { cout << i << endl; break; } } return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int gcd(int a, int b) { int t; while (b) { t = a % b; a = b; b = t; } return a; } int main(void) { int a, b; scanf("%d%d", &a, &b); printf("%d\n", b / gcd(a, b)); return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int p, q; cin >> p >> q; int x = 1, a = p, b = q; for (int i = 2; i <= p; ++i) { if (a % i == 0 && b % i == 0) while (a % i == 0 && b % i == 0) { x *= i; a /= i, b /= i; } } cout << q / x << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int p, q; vector<int> primes; const int MA = 10000000; bool t[MA * 2]; void eratosu() { t[1] = 1; for (int i = 2; i <= MA; i++) { if (t[i] == 0) { primes.push_back(i); for (int j = i * 2; j <= MA; j += i) t[j] = 1; } } } int main() { eratosu(); cin >> p >> q; for (int i = 0; i < primes.size(); i++) { int now = primes[i]; if (now > p || now > q) break; while (p % now == 0 && q % now == 0) p /= now, q /= now; } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 29; const long long INF = 1ll << 62; const double pi = acos(-1); const double eps = 1e-7; const long long mod = 1e9 + 7; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long p, q; int main() { cin >> p >> q; cout << q / gcd(p, q) << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int main(){ int p,q; cin>>p>>q; p=q/__gcd(p,q); int f=0; for(int i=2;i*i<p;i++){ if(p%i)continue; f=i; break; } if(f==0){ cout<<p<<endl; return 0; } int t=p; while(t%f==0&&t!=1)t/=f; if(t==1)cout<<f<<endl; else cout<<p<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<bits/stdc++.h> #define N 100005 using namespace std; int p,q,t,ans,prime[N]; set<int> s; int main(){ for(int i=0;i<N;i++)prime[i]=1; prime[0]=prime[1]=0; for(int i=0;i*i<N;i++){ if(!prime[i])continue; for(int j=i*2;j<N;j+=i) prime[j]=0; } cin>>p>>q; t=q/__gcd(p,q); for(int i=0;i*i<=t;i++) if(prime[i]&&!(t%i)){ s.insert(i); if(prime[t/i])s.insert(t/i); } ans=1; set<int>::iterator ite=s.begin(); while(ite!=s.end()){ cout<<*ite<<endl; ans*=(*ite); ite++; } cout<<ans<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } queue<long long int> q; vector<bool> prime(1000000000 + 1, true); void make(long long int M) { prime[0] = prime[1] = false; for (long long int i = 2; i * i < M + 1; i++) { if (prime[i]) { long long int j = 2; q.push(i); while (i * j < M + 1) { prime[i * j] = false; j++; } } } return; } int main() { long long int a, b; cin >> a >> b; make(max(a, b)); long long int c = b / gcd(a, b); long long int ans = 1; long long int ma = c; while (!q.empty()) { long long int d = q.front(); if (c % d == 0) { ans *= d; } q.pop(); } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
// // Created by 拓真 on 2018/06/30. // #include "bits/stdc++.h" using namespace std; #define FOR(i,a,b) for(int i=a;i<b;i++) #define rep(i,b) FOR(i,0,b) #define int long long int era[112345678]; void eratos(){ for(int i=0;i<112345;i++)era[i]=1; era[0]=0; era[1]=0; for(int tar=2;tar<112345;tar++){ int bai=tar; if(era[bai]==1){ //era[bai]=0; for(int i=2;bai*i<112345;i++) { era[bai * i] = 0; } } } } signed main(){ int p,q; cin>>p>>q; p/=__gcd(p,q); q/=__gcd(p,q); eratos(); vector<int> sosu; rep(i,112345){ if(era[i])sosu.push_back(i); } vector<int> bun; rep(i,sosu.size()){ if((int)q%sosu[i]==0){ bun.push_back(sosu[i]); } } int ans=1; rep(i,(int)bun.size()&&__gcd(bun[i],p)==1){ ans*=bun[i]; } cout<<ans<<endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
def gcd(a, b): if a < b: a, b = b, a if b == 0: return a c = a % b return gcd(b, c) p, q = map(int, input().split()) g = gcd(p, q) p //= g q //= g ret = q for b in range(1, 40000): if b ** 1000 * p % q == 0: ret = min(ret, b) print(ret)
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { long long p, q; cin >> p >> q; long long m = 1; for (int i = 1; i <= p; i++) { if (p % i == 0 && q % i == 0) { m = i; } } cout << q / m << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(x * a, y * a); } Point operator/(double a) { return Point(x / a, y / a); } double absv() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10); } }; struct Segment { Point p1, p2; }; double hen(Point a) { if (fabs(a.x) < (1e-10) && a.y > 0) return acos(0); else if (fabs(a.x) < (1e-10) && a.y < 0) return 3 * acos(0); else if (fabs(a.y) < (1e-10) && a.x < 0) return 2 * acos(0); else if (fabs(a.y) < (1e-10) && a.x > 0) return 0.0; else if (a.y > 0) return acos(a.x / a.absv()); else return 2 * acos(0) + acos(-a.x / a.absv()); } string itos(long long i) { ostringstream s; s << i; return s.str(); } long long gcd(long long v, long long b) { if (v > b) return gcd(b, v); if (v == b) return b; if (b % v == 0) return v; return gcd(v, b % v); } double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } double distans(double x1, double y1, double x2, double y2) { double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); return sqrt(rr); } bool b[100020] = {0}; signed main() { b[1] = 1; for (long long i = 2; i < 100020; i++) { if (b[i] == 1) continue; long long d = 2 * i; while (d < 100020) { b[d] = 1; d += i; } } long long n, m; cin >> n >> m; m = m / gcd(n, m); vector<long long> ve; for (long long i = 2; i < 100020; i++) { if (b[i] == 1) continue; long long ko = 0; while (1) { if (m % i == 0) { m /= i; ko++; if (ko == 1) ve.push_back(i); } else break; } } if (m > 1) ve.push_back(m); long long ans = 1; for (long long i = 0; i < ve.size(); i++) ans += ve[i]; cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
#import math p, q = map(int, input().split()) #g = math.gcd(p, q) #p //= g #q //= g ret = q for b in range(1, 40000): if b ** 1000 * p % q == 0: ret = min(ret, b) print(ret)
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int p, q; cin >> p >> q; for (int i = 2; i < 1e9; i++) { if (q % i == 0 && p % (q / i) == 0) { cout << i << endl; break; } } return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 50; int solve(); long long gcd(long long p, long long q) { if (q == 0) { return p; } return gcd(q, p % q); } int main(void) { while (solve()) { } return 0; } int solve() { long long p, q, g; cin >> p >> q; g = gcd(max(p, q), min(p, q)); p = p / g; q = q / g; const long long M = sqrt(10e15); std::vector<bool> isPrime(M, true); isPrime[1] = false; for (long long i = 2; i < M; i++) { if (isPrime[i] == false) { continue; } for (long long j = 2; i * j < M; j++) { isPrime[i * j] = false; } } long long ans = 1; for (long long i = 2; i < M; i++) { if (isPrime[i] == true && q % i == 0) { ans *= i; } } if (ans == 1 && q > 1) { ans = q; } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Scanner; public class Main{ public static void main(String args[]) { Scanner scn = new Scanner(System.in); long p = scn.nextLong(), q = scn.nextLong(); scn.close(); long qs; long ans; long bp = p,bq = q,buf = p; while(bq % bp != 0) { buf = bq % bp; bq = bp; bp = buf; } ans = q/buf; for(int i = 2;i <= Math.sqrt(q/buf);i++) { for(int j = 1;j <= buf;j++) { if(p%j == 0 && q %j == 0) { qs = q/j; while(qs % i == 0) { qs /= i; } if(qs == 1) { ans = i; break; } } } } System.out.println(ans % buf == 0?ans/buf:ans); } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using std::cerr; using std::cin; using std::cout; using std::endl; int gcd(int p, int q) { if (q > p) std::swap(p, q); while (p % q != 0) { int r = p % q; p = q; q = r; } return q; } int main(void) { cout << std::fixed << std::setprecision(10); cin.tie(0); std::ios::sync_with_stdio(false); int p, q; cin >> p >> q; int div = gcd(p, q); p /= div; q /= div; for (int i = 2; i < 100000; i++) { int tgt = q; while (tgt % q == 0) { tgt /= q; } if (tgt == 1) { cout << q << endl; return 0; } } return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int p, q; cin >> p >> q; int ans = 1; for (int i = 2; i <= q; i++) { if (q % i != 0) continue; ans *= i; while (q % i == 0) q /= i; } cout << ans << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define INF 1001000100010001000 #define MOD 1000000007 #define EPS 1e-10 #define int long long #define rep(i, N) for (int i = 0; i < N; i++) #define Rep(i, N) for (int i = 1; i < N; i++) #define For(i, a, b) for (int i = (a); i < (b); i++) #define pb push_back #define mp make_pair #define i_i pair<int, int> #define vi vector<int> #define vvi vector<vi > #define vb vector<bool> #define vvb vector<vb > #define vp vector< i_i > #define all(a) (a).begin(), (a).end() #define Int(x) int x; scanf("%lld", &x); //int dxy[5] = {0, 1, 0, -1, 0}; // assign?? vi prime; int gcd(int a, int b) { if (a == 1) { return b; } else { return gcd(b, b%a); } } void pri() { vector<bool> state(5001, false); for (int i = 2; i < 5000; i++) { if (!state[i]) { prime.pb(i); for (int j = 2; i*j < 5000; j++) { state[i*j] = true; } } } } signed main() { pri(); Int(p) Int(q) while (p && q) { if ( p >= q) { cout << 2 << endl; } else { int ret = gcd(p, q); int ans = 1; while (ret != 1) { rep(i, prime.length()) { if (!(ret % prime[i])) { ans *= prime[i]; ret /= prime[i]; }}} cout << ans << endl; } cin >> p >> q;} return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second int main() { int p,q; cin >>p >>q; int g=__gcd(p,q); p/=g; q/=g; int ans=q; for(int i=2; i*i<=q; ++i) { int t=i; while(t*i<=q) t*=i; if(t==q) { ans=i; break; } } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; using Ti = tuple<int, int, int>; using Tl = tuple<ll, ll, ll>; #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define F first #define S second #define Get(t, i) get<(i)>((t)) #define all(v) (v).begin(), (v).end() #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++) #define each(a, b) for(auto& a : b) const int inf = 1 << 25; const ll INF = 1LL << 55; int main() { ll p, q; cin >> p >> q; vector<int> factor; q = q / __gcd(p, q); for(int x = 2; x*x <= q; x++) { if(q % x == 0) { factor.push_back(x); while(q % x == 0) q /= x; } } if(q != 1) factor.push_back(q); ll ans = 1; rep(i, factor.size()) ans *= factor[i]; cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(){ int p,q; cin>>p>>q; int a=__gcd(p,q); p/=a,q/=a; for(int i=2;i*i<=q;i++){ if(q%i!=0)continue; int b=q/i; while(q%(i*i)==0)q/=i; while(q%(b*b)==0)q/=b; } cout <<q<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vector<PII>; template <typename T> using VT = vector<T>; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; const double EPS = 1e-18; bool ok(double n, int p) { set<string> se{to_string(n)}; while (true) { n *= p; n -= (int)n; if (n - EPS <= 0) return true; if (se.count(to_string(n))) return false; se.insert(to_string(n)); } } void solve(int p, int q) { double div = 1. * p / q; for (int i = 2;; i++) { if (ok(div, i)) { printf("%d\n", i); return; } } return; } signed main(void) { LL n, m, p, a, b, c, x, y, z, q; string s; bool f = false; while (cin >> n >> m, n) { solve(n, m); return 0; } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (a && b) { if (a >= b) a %= b; else b %= a; } return a + b; } int main() { ios::sync_with_stdio(false); cin.tie(0); int p, q; cin >> p >> q; int x = gcd(p, q); cout << q / x << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } void solve() { int p, q; cin >> p >> q; int r = sqrt(p); while (p != 1 && r * r == p) { p = r; r = sqrt(r); } r = sqrt(q); while (q != 1 && r * r == q) { q = r; r = sqrt(r); } cout << q / gcd(p, q) << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(); solve(); }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { static PrintWriter out; static InputReader ir; static void solve() { int p = ir.nextInt(); if(p==0){ out.println(2); System.exit(0); } int q = ir.nextInt(); int a = q / gcd(p, q); boolean[] prime=sieveOfEratosthenes(a); int ret=1; for(int i=1;i<=Math.sqrt(a);i++){ if(!(a%i==0)) continue; if(prime[i]) ret*=i; if(prime[a/i]) ret*=a/i; } out.println(ret); } public static boolean[] sieveOfEratosthenes(int n) { boolean[] res = new boolean[n + 1]; Arrays.fill(res, true); res[0] = res[1] = false; for (int i = 2; i <= Math.sqrt(n); i++) { if (res[i]) { for (int j = i + i; j <= n; j += i) { res[j] = false; } } } return res; } public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) throws Exception { ir = new InputReader(System.in); out = new PrintWriter(System.out); solve(); out.flush(); } static class InputReader { private InputStream in; private byte[] buffer = new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) { this.in = in; this.curbuf = this.lenbuf = 0; } public boolean hasNextByte() { if (curbuf >= lenbuf) { curbuf = 0; try { lenbuf = in.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return false; } return true; } private int readByte() { if (hasNextByte()) return buffer[curbuf++]; else return -1; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private void skip() { while (hasNextByte() && isSpaceChar(buffer[curbuf])) curbuf++; } public boolean hasNext() { skip(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[][] nextCharMap(int n, int m) { char[][] map = new char[n][m]; for (int i = 0; i < n; i++) map[i] = next().toCharArray(); return map; } } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long solve(long long a, long long b) { long long x = max(a, b), y = min(a, b); if (x % y == 0) return y; else return solve(x % y, y); } int main() { long long p, q, r, ans; vector<long long> prime(100000); cin >> p >> q; r = solve(p, q); p /= r; q /= r; long long i = 2, j = 0, temp = q; while (temp != 1) { if (temp % i == 0) { temp /= i; prime[j]++; } else { if (i == 2) i = 3; else { double ii; ii = static_cast<double>(i); if (ii > pow(temp, 0.5)) { j++; prime[j]++; break; } else i += 2; } if (prime[j] > 0) j++; } } sort(prime.begin(), prime.begin() + j); if (prime[0] == 1) ; else { long long k = 2; while (prime[0] != 1 && prime[0] >= k) { if (prime[0] % k == 0) { int all = 1; for (int l = 0; l < j; l++) { if (prime[l] % k != 0) { if (k == 2) k = 3; else k += 2; all = 0; break; } } if (all = 1) { long long qq; double kk; kk = static_cast<double>(k); qq = pow(q, 1 / kk); if (q % qq > 0) q = qq; else q = qq; for (int l = 0; l <= j; l++) prime[l] /= k; } } else { if (k == 2) k = 3; else k += 2; } } } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.BitSet; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { static PrintWriter out; static InputReader ir; static void solve() { int p=ir.nextInt(); int q=ir.nextInt(); out.println(q/gcd(p,q)); } public static int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } public static void main(String[] args) throws Exception { ir = new InputReader(System.in); out = new PrintWriter(System.out); solve(); out.flush(); } static class InputReader { private InputStream in; private byte[] buffer = new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) { this.in = in; this.curbuf = this.lenbuf = 0; } public boolean hasNextByte() { if (curbuf >= lenbuf) { curbuf = 0; try { lenbuf = in.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return false; } return true; } private int readByte() { if (hasNextByte()) return buffer[curbuf++]; else return -1; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private void skip() { while (hasNextByte() && isSpaceChar(buffer[curbuf])) curbuf++; } public boolean hasNext() { skip(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[][] nextCharMap(int n, int m) { char[][] map = new char[n][m]; for (int i = 0; i < n; i++) map[i] = next().toCharArray(); return map; } } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; int gcd(int p, int q) { int p_temp; while (1) { if (q == 0) { break; } p_temp = p; p = q; q = p_temp % q; } return p; } int main(void) { int p; int q; cin >> p >> q; cout << q / gcd(p, q) << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long solve(long long a, long long b) { long long x = max(a, b), y = min(a, b); if (x % y == 0) return y; else return solve(x % y, y); } int main() { long long p, q, r, ans; vector<long long> prime(100000); cin >> p >> q; r = solve(p, q); p /= r; q /= r; long long i = 2, j = 0, temp = q; while (temp != 1) { if (temp % i == 0) { temp /= i; prime[j]++; } else { if (i == 2) i = 3; else i += 2; if (prime[j] > 0) j++; } } sort(prime.begin(), prime.begin() + j); if (prime[0] == 1) ; else { long long k = 2; while (prime[0] != 1 && prime[0] >= k) { if (prime[0] % k == 0) { int all = 1; for (int l = 0; l < j; l++) { if (prime[l] % k != 0) { if (k == 2) k = 3; else k += 2; all = 0; break; } } if (all = 1) { double kk; kk = k; q = pow(q, 1 / kk); for (int l = 0; l <= j; l++) prime[l] /= k; } } else { if (k == 2) k = 3; else k += 2; } } } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } void solve() { int p, q; cin >> p >> q; cout << q / gcd(p, q) << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(); solve(); }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long gcd(long a, long b) { return b ? gcd(b, a % b) : a; } long a, b; int main() { cin >> a >> b; b /= gcd(a, b); for (long i = 2; i * i <= b; i++) { for (long j = i * i; j <= b; j *= i) { if (b == j) { cout << i << endl; return 0; } } } cout << b << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long p, q; vector<int> yakusuu; int main() { cin >> p >> q; for (int i = 1; i <= p / 2; i++) { if (p % i == 0) { yakusuu.push_back(i); } } for (int j = 0; j < yakusuu.size(); j++) { if (q % yakusuu[j] == 0) q = q / yakusuu[j]; } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int p, q; cin >> p >> q; q = q / gcd(p, q); vector<int> v; cout << q << endl; for (int i = 2; i * i <= q; i++) { if (q % i == 0) { v.push_back(i); while (q % i == 0) q /= i; } } int r = 1; for (int i = 0; i < v.size(); i++) r *= v[i]; cout << r * q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } queue<long long int> q; vector<bool> prime(1000000000 + 1, true); void make(long long int M) { prime[0] = prime[1] = false; long long int i; for (i = 2; i * i <= M + 1; i++) { if (prime[i]) { long long int j = 2; q.push(i); while (i * j < M + 1) { prime[i * j] = false; j++; } } } for (; i <= M; i++) { if (prime[i]) q.push(i); } return; } int main() { long long int a, b; cin >> a >> b; make(max(a, b)); long long int c = b / gcd(a, b); long long int ans = 1; long long int ma = c; while (!q.empty()) { long long int d = q.front(); if (c % d == 0) { ans *= d; } q.pop(); } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 50; int solve(); long long gcd(long long p, long long q) { if (q == 0) { return p; } return gcd(q, p % q); } int main(void) { while (solve()) { } return 0; } int solve() { long long p, q, g; cin >> p >> q; g = gcd(max(p, q), min(p, q)); p = p / g; q = q / g; long long ans = 1; const long long M = 10e9; if (q > 1) for (long long i = 2; i < M; i++) { long double d = logl(q) / logl(i); if (abs(d - static_cast<long long>(d)) < 10e-8) { ans = i; break; } } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int euclid(int x, int y) { int t; while (x % y) { x %= y; t = x; x = y; y = t; } return y; } int main() { int p, q, n, m, t = 2, ans = 1; cin >> p >> q; n = q / euclid(p, q); m = n; map<int, int> f; while (n > 1 && t < sqrt(m)) { if (!(n % t)) { n /= t; f[t] = 1; } while (!(n % t)) { ++f[t]; n /= t; } ++t; } if (n != 1) f[n] = 1; m = q; for (auto itr = f.begin(); itr != f.end(); ++itr) m = min(m, itr->second); for (auto itr = f.begin(); itr != f.end(); ++itr) { m = euclid(m, itr->second); } for (auto itr = f.begin(); itr != f.end(); ++itr) { for (int i = 0; i < itr->second / m; ++i) { ans *= itr->first; } } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.*; public class Main{ public static void main(String args[]){ try(Scanner sc = new Scanner(System.in)){ long p = sc.nextLong(), q = sc.nextLong(); long memo = q/gcd(p,q); long ans = memo; int i = 0; long[] X = new long[10000]; long x = 2; while(memo!=1){ while(memo%x==0){ X[i++]=x; memo/=x; } x++; } if(X[0]==X[i-1]){ System.out.println(X[0]); } else { System.out.println(ans); } } } private static long gcd(long p, long q){ if(p < q) { return gcd(q, p); } if(q==0){ return p; } return gcd(q, p%q); } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Integer.parseInt; /** * Let's Solve Geometric Problems */ public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; String[] words; line = br.readLine(); long p, q; p = parseInt(line.substring(0, line.indexOf(' '))); q = parseInt(line.substring(line.indexOf(' ') + 1)); System.out.println(q / gcd(p, q)); }//end main static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int main(){ int q,p,t,ans=1,i,j,c=0; cin>>q>>p;t=p; p/=__gcd(q,p); if(p!=t)for(i=2;i*i<=t;i++){ if(p%i==0){ p/=i; ans*=i; i--; } } else ans=t; cout<<ans<<endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 50; int solve(); long long gcd(long long p, long long q) { if (q == 0) { return p; } return gcd(q, p % q); } int main(void) { while (solve()) { } return 0; } int solve() { long long p, q, g; cin >> p >> q; g = gcd(max(p, q), min(p, q)); p = p / g; q = q / g; const long long M = sqrt(10e10); std::vector<bool> isPrime(M, true); isPrime[1] = false; for (long long i = 2; i < M; i++) { if (isPrime[i] == false) { continue; } for (long long j = 2; i * j < M; j++) { isPrime[i * j] = false; } } long long ans = 1; for (long long i = 2; i < M; i++) { if (isPrime[i] == true && q % i == 0) { ans *= i; } } if (ans == 1 && q > 1) { ans = q; } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int p, q, mi; cin >> p >> q; mi = (p, q); while (p % q == 0) { if (q == 1) break; p /= q; q /= q; } for (int i = 2; i * i <= mi; i++) { while (p % i == 0 && q % i == 0) { p /= i; q /= i; } while (q % (mi / i) == 0 && p % (mi / i) == 0) { p /= mi / i; q /= mi / i; } } cout << q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { long long p, q; cin >> p >> q; long long m = 1; for (int i = 1; i <= p; i++) { if (p % i == 0 && q % i == 0) { m = i; } } cout << q / m << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int p, q, x, test; cin >> p >> q; if (p < q) swap(p, q); test = p; while (1) { if (p % q != 0) { x = p % q; p = q; q = x; continue; } break; } cout << test / q << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int euclid(int x, int y) { int t; while (x % y) { x %= y; t = x; x = y; y = t; } return y; } int main() { int p, q, n, m, t = 2, ans = 1; cin >> p >> q; n = q / euclid(p, q); m = n; map<int, int> f; while (n > 1 && t < sqrt(m) + 1) { if (!(n % t)) { n /= t; f[t] = 1; } while (!(n % t)) { ++f[t]; n /= t; } ++t; } if (n != 1) f[n] = 1; m = q; for (auto itr = f.begin(); itr != f.end(); ++itr) m = min(m, itr->second); for (auto itr = f.begin(); itr != f.end(); ++itr) { m = euclid(m, itr->second); } for (auto itr = f.begin(); itr != f.end(); ++itr) { for (int i = 0; i < itr->second / m; ++i) { ans *= itr->first; } } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::fixed; using std::list; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::setprecision; using std::stack; using std::string; using std::vector; int gcd(int p, int q) { int temp; if (q == 0) { return p; } else { temp = p % q; p = q; q = temp; return gcd(p, q); } return 0; } bool prime_check(int number) { if (number == 2) { return true; } else if (number % 2 == 0) { return false; } for (int i = 3; i * i <= number; i++) { if (number % i == 0) { return false; } } return true; } int main(void) { int p; int q; int ans = 1; cin >> p >> q; q /= gcd(p, q); for (int i = 2; i <= q; i++) { if (prime_check(i) == true && q / q != 0) { ans *= i; } } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { long long int p, q; cin >> p >> q; q /= gcd(p, q); for (int i = 2; i < 32000; i++) { double x = log(q) / log(i); if (ceil(x) == floor(x)) { cout << i << endl; return 0; } } cout << q << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<long long> prime; long long gcd(long long a, long long b) { if (a == 1) { return b; } else { return gcd(b, b % a); } } void pri() { vector<bool> state(5001, false); for (long long i = 2; i < 5000; i++) { if (!state[i]) { prime.push_back(i); for (long long j = 2; i * j < 5000; j++) { state[i * j] = true; } } } } signed main() { pri(); long long p; scanf("%lld", &p); long long q; scanf("%lld", &q); while (p && q) { if (p >= q) { cout << 2 << endl; } else { long long ret = gcd(p, q); long long ans = 1; while (ret != 1) { for (long long i = 0; i < prime.size(); i++) { if (!(ret % prime[i])) { ans *= prime[i]; ret /= prime[i]; } } } cout << ans << endl; } cin >> p >> q; } return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int main(){ int p,q,t,ans=1,num; set<int> s; cin>>p>>q; num=t=q/__gcd(p,q); for(int i=2;i<=num;i++){ if(!(num%i)){ s.insert(i); while(!(num%i))num/=i; } } set<int>::iterator ite=s.begin(); while(ite!=s.end())ans*=*ite,ite++; if(ans==1)ans=t; cout<<ans<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int main(){ int p,q,t,ans; cin>>p>>q; ans=t=q/__gcd(p,q); for(int i=2;i*i<=t;i++) if(i*i==t)ans=i; cout<<ans<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int in(void) { int i; scanf("%d", &i); return i; } long long llin(void) { long long i; scanf("%lld", &i); return i; } void print(int a) { printf("%d\n", a); } void llprint(long long a) { printf("%lld\n", a); } void print2(int a, int b) { printf("%d %d\n", a, b); } long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } int main(void) { int p = in(), q = in(); int g = gcd(p, q); int i, j; p /= g; q /= g; for (i = 2; i < q; i++) { for (j = 1; j <= q; j *= i) { if (j == q) { q = i; break; } } } print(q); return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int p, q; vector<int> primes; const int MA = 30000000; bool t[MA * 2]; void eratosu() { t[1] = 1; for (int i = 2; i <= MA; i++) { if (t[i] == 0) { primes.push_back(i); for (int j = i * 2; j <= MA; j += i) t[j] = 1; } } } bool check(int x) { int a = x; int aa = x; while (aa <= q) { if (aa == q) return 1; aa = aa * a; } return 0; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { eratosu(); cin >> p >> q; int gc = gcd(p, q); int np = p, nq = q; p = np / gc; q = nq / gc; int ans = 1, qq = q; for (int i = 0; i < primes.size(); i++) { int now = primes[i]; if (q % now == 0) ans *= now; while (q % now == 0) q /= now; } cout << ans << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<bits/stdc++.h> #define N 100005 using namespace std; int p,q,t,ans,prime[N]; set<int> s; int main(){ for(int i=0;i<N;i++)prime[i]=1; prime[0]=prime[1]=0; for(int i=0;i*i<N;i++){ if(!prime[i])continue; for(int j=i*2;j<N;j+=i) prime[j]=0; } cin>>p>>q; t=q/__gcd(p,q); for(int i=0;i*i<=t;i++) if(prime[i]&&!(t%i)){ s.insert(i); if(prime[t/i])s.insert(t/i); } ans=1; set<int>::iterator ite=s.begin(); while(ite!=s.end()){ ans*=(*ite); ite++; } if(ans==1)ans=t; cout<<ans<<endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int COU(int a, int b) { if (a == b || a == 0) return 1; while (true) { if (a < b) { int t = a; a = b, b = t; } if (b == 0) return a; a %= b; } } int main() { int p, q; cin >> p >> q; cout << q / COU(p, q) << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; struct UnionFind { vector<int> v; UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; } int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); } void unite(int x, int y) { v[find(x)] = find(y); } }; long long gcd(long long a, long long b) { if (a < b) swap(a, b); while (a % b != 0) { a %= b; swap(a, b); } return b; } int main() { map<int, int> mpii; for (int i = (int)(1); i < (int)(40000); ++i) mpii[i * i] = i; int p, q; cin >> p >> q; q /= gcd(p, q); set<int> soinsu; for (int i = (int)(2); i < (int)(sqrt(q) + 100); ++i) { while (q % i == 0) { q /= i; soinsu.insert(i); } } long long ans = 1; for (int a : soinsu) ans *= a; cout << ans << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { int p, q; cin >> p >> q; int g = __gcd(p, q); int b = q / g; rep(i, 100005) if (i > 1) { while (b % i == 0 && b / i != 1) b /= i; } cout << b << endl; return 0; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int p, q; cin >> p >> q; int d = gcd(p, q); cout << q / d << endl; }
p01809 Let's Solve Geometric Problems
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits. Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one. Constraints * 0 <p <q <10 ^ 9 Input Format Input is given from standard input in the following format. p q Output Format Print the answer in one line. Sample Input 1 1 2 Sample Output 1 2 1/2 is binary 0.1 Sample Input 2 21 30 Sample Output 2 Ten 21/30 is 0.7 in decimal Example Input 1 2 Output 2
{ "input": [ "1 2" ], "output": [ "2" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x % y)); } int main() { int P, Q; cin >> P >> Q; int G = gcd(P, Q); cout << std::max(2, Q / G) << endl; return 0; }