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": [] }
CORRECT
java
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int P = sc.nextInt(); int Q = sc.nextInt(); Q /= gcd(P, Q); int ans = 1; for (int i = 2; i * i <= Q; i++) { if (Q % i == 0) { while (Q % i == 0) { Q /= i; } ans *= i; } } ans *= Q; System.out.println(ans); } static int gcd(int a, int b) { return b == 0 ? a : 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": [] }
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 if t % 2 == 0: k *= 2 while t % 2 == 0: t //= 2 for i in range(3,int(math.sqrt(t))+2,2): if t % i > 0: continue k *= i while t % i == 0: t //= i 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": [] }
CORRECT
python3
def gcd(a, b): while b: a, b = b, a % b return a a,b=map(int,input().split()) b//=gcd(a,b) a,c=2,1 while a*a<=b: if b%a==0: c*=a while b%a==0:b//=a a+=1 print([c*b,c][b==1])
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": [] }
CORRECT
cpp
#include<iostream> #include <list> #include<stack> #include<queue> #include <vector> #include <set> #include<algorithm> #include<math.h> #include<stdlib.h> #include<string> #include <functional> #include<fstream> #define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++) #define REP(i,n) FOR((i),0,(n)) #define LL long long #define CLR(a) memset((a),0,sizeof(a)) #define SZ(x) (int((x).size())) #define WAITING(str) int str;std::cin>>str; #define DEBUGING(str) cout<<str<<endl using namespace std; const LL MOD = 1000000007;// 10^9+7 const int INF = (1 << 30); //変数 LL p, q; //素因数分解 //in: number //out: prime numbers template<typename T> vector<T> prime_factorization(T n) { vector<T> res; T check = 2; while (check*check <= n) { if (n%check == 0) { n /= check; res.push_back(check); } else { check++; } } if (n != 1) res.push_back(n); sort(res.begin(), res.end()); return res; } //最大公約数 //(ユークリッドの互除法) //in: a,b //out: GCD(a,b) template<typename T> T GCD(T a, T b) { if (a < b)swap(a, b); int r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } //サブ関数 //入力 void input() { cin >> p >> q; } //計算 void calc() { LL gcd = GCD(p, q); q /= gcd; auto primes = prime_factorization(q); set<LL> primeKind; for (auto prime : primes)primeKind.insert(prime); LL res = 1; for (auto prime : primeKind)res *= prime; cout << res << endl; } //出力 void output() { } //デバッグ void debug() { int N; cin>>N; } //メイン関数 int main() { input(); calc(); output(); debug(); 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef pair<ll,P> PP; const long long int MOD = 1000000007; const int INF = 1000000000; int p, q; int main(){ cin >> p >> q; int pp = p, qq = q; while(qq){ pp %= qq; swap(pp,qq); } q /= pp; int ans = 1; for(int i = 2;;i++){ if(i*i > q) break; if(q%i == 0){ ans *= i; } while(q%i == 0){ q /= i; } } ans *= q; 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": [] }
CORRECT
cpp
#include "bits/stdc++.h" using namespace std; //#define int long long #define DBG 1 #define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;} #define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;} #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define each(it,c) for(auto it=(c).begin();it!=(c).end();it++) #define all(c) c.begin(),c.end() const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9 + 7); //?????§??¬?´???° int gcd(int x, int y) { return y ? gcd(y, x%y) : x; } //?????????: n??\???????´???° vector<int> getPrimes(int n) { vector<char> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; for (int i = 2; i*i <= n; i++) if (is_prime[i]) { int j = i + i; while (j <= n) { is_prime[j] = false; j += i; } } vector<int> primes; rep(i, 0, n + 1) if (is_prime[i]) primes.emplace_back(i); return primes; } //?´??????°????§£ vector<int> primeFactorization(int x) { vector<int> primes = getPrimes(sqrt(x)); //???x??\???????´???°???????????????????????°?????? vector<int> factors; for (auto &p : primes) { while (x%p == 0) { x /= p; factors.emplace_back(p); } } if (x != 1)factors.emplace_back(x); return factors; } //??§?¨???§??? vector?????????????´?????????? //v: ??§???????????§?¨??????? ???????????? template<typename T> void compress(vector<T> &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } signed main() { int p, q; cin >> p >> q; int g = gcd(p, q); int a = q / g; int ans = 1; vector<int> factors = primeFactorization(a); compress(factors); rep(i, 0, factors.size()) { ans *= factors[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": [] }
CORRECT
cpp
#include <iostream> #include <cmath> using std::cin; using std::cout; using std::endl; int gcd(int n, int m) { if ( n%m == 0 ) { return m; } else { return gcd(m,n%m); } } int main(void) { int p,q; cin >> p >> q; int n = q; int m = p; int l = gcd(n,m); while ( l != 1 ) { n = n/l; m = m/l; l = gcd(n,m); } while ( (int)sqrt(n) == sqrt(n) ) { n = sqrt(n); } for (int i = 2; i*i < n+1; i++) { if ( n%(i*i) == 0 ) { n = n/i; i--; } } cout << n << 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": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <vector> #include <queue> #include <sstream> using namespace std; long long int LCM(long long int a, long long int b){ long long int dummy1, dummy2, dummy; dummy1 = max(a, b); dummy2 = min(a, b); while(true){ dummy = dummy1 % dummy2; dummy1 = dummy2; dummy2 = dummy; if(dummy == 0){ break; } } return (a / dummy1) * (b / dummy1) * dummy1; } long long int GCD(long long int a, long long int b){ long long int dummy1, dummy2, dummy; dummy1 = max(a, b); dummy2 = min(a, b); while(true){ dummy = dummy1 % dummy2; dummy1 = dummy2; dummy2 = dummy; if(dummy == 0){ break; } } return dummy1; } int main(){ int N = 100000; bool a[100000]; for(int i = 0; i < N; i++){ a[i] = true; } a[0] = false; a[1] = false; for(int i = 2; i < N; i++){ if(a[i]){ for(int j = i * 2; j < N; j += i){ a[j] = false; } } } long long int p, q; cin >> p >> q; q = q / GCD(p, q); long long int ans = 1; long long int sq_q = sqrt(q); for(int i = 1; i <= sq_q; i++){ if(a[i] && q % i == 0){ ans *= i; while(q % i == 0){ q /= i; } } } 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": [] }
CORRECT
cpp
#include"bits/stdc++.h" using namespace std; using ll = int64_t; ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } bool isPrime(ll n) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } int main() { ll p, q; cin >> p >> q; ll tar = q / gcd(p, q); if (isPrime(tar)) { cout << tar << endl; return 0; } ll ans = 1; for (ll i = 2; i * i <= tar; i++) { if (tar % i == 0) { ans *= i; while (tar % i == 0) { tar /= i; } if (isPrime(tar)) { ans *= tar; break; } } } 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": [] }
CORRECT
java
import java.util.ArrayList; import java.util.Scanner; public class Main{ public static void main(String args[]) { ArrayList<Long> yaku = new ArrayList<Long>(); Scanner scn = new Scanner(System.in); long p = scn.nextLong(), q = scn.nextLong(); scn.close(); long qs; long ans = 1; long bp = p,bq = q,buf = p; while(bq % bp != 0) { buf = bq % bp; bq = bp; bp = buf; } qs = q/buf; for(long i = 2;i <= Math.sqrt(qs);i++) { if(qs % i ==0) { while(qs % i == 0) { qs /=i; } ans *= i; } } ans*= qs; System.out.println(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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define show(x) cout <<#x<<" = "<<(x)<<endl #define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl #define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl #define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl using namespace std; typedef pair<int,int>P; const int MAX_N = 100005; 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)); int ans = 1; for(int i=2;i<=mx;i++){ if(q % i == 0){ ans *= i; while(q % i == 0){ q /= i; } } } if(q != 1){ ans *= q; } cout << ans << "\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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int Prime[100000]={}; void pr(){ Prime[0]=2; int tmp=1,num=1; while(num<100000){ num+=2; int flag=0; for(int i=3;i<=sqrt(num);i+=2) if(num%i==0) flag++; if(flag==0) Prime[tmp++]=num; } } int gcd(int x,int y){ return y?gcd(y,x%y):x; } int main(){ pr(); int p,q; cin>>p>>q; int a=q/gcd(p,q); //while(sqrt(a)*sqrt(a)==a) a=sqrt(a); for(int i=0;a/Prime[i]>=Prime[i];++i){ int tmp=a; while(a%Prime[i]==0) a=a/Prime[i]; if(tmp!=a) a*=Prime[i]; } 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": [] }
CORRECT
cpp
#include <iostream> using namespace std; int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } int main() { int p, q; cin >> p >> q; while (true) { int g = gcd(p, q); if (g == 1) { break; } p /= g; q /= g; } int t = q; int ans = 1; for (int i = 2; i * i <= q; i++) { if (t % i == 0) { ans *= i; while (t % i == 0) { t /= i; } } } 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define first fi; #define second se; using namespace std; typedef pair<int, int> P; int gcd(int a, int b){ if(a < b) swap(a, b); if(b == 0) return a; return gcd(b, a % b); } signed main(){ int p, q; cin >> p >> q; q /= gcd(p, q); int ans = 1; for(int i = 2; i * i <= q; i++){ if(q % i == 0) ans *= i; while(q % i == 0){ q /= i; } } if(q != 1) ans *= q; 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": [] }
CORRECT
python3
prime = [2] def check(x): for i in prime: if x % i ==0: return False elif x < i * i: break return True def set(): for i in range(3,10**5,2): if check(i): prime.append(i) set() #print('ok') #print(prime) p,q = [int(i) for i in input().split(' ')] if q % p == 0: q = q //p p = 1 for i in prime: while True: if p % i ==0 and q % i == 0: p = p // i q = q // i #print(p,q,i) else: break ans = 1 #print(p,q) for i in prime: if q % i == 0: # print(q,i) q = q // i ans *= i while q % i ==0: q = q // i ans *= q print(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": [] }
CORRECT
cpp
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> #include <cstring> using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) #define CLR(mat) memset(mat, 0, sizeof(mat)) typedef long long ll; // b^k???q????´???°??¨????????? //?????§??¬?´???° 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; q /= gcd(p, q); int qq = q; int ans = 1; for(int i = 2; i * i <= qq; i++) { if(q % i == 0) { while(q % i == 0) { q /= i; } ans *= i; } } if(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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; vector<LLi> pri={1, 2, 3}; void PV(vector<int> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } void PVL(vector<LLi> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } bool VV(vector<int> vv1, vector<int> vv2) { if(vv1.size()!=vv2.size()) return false; rep(i, vv1.size()) if(vv1[i]!=vv2[i]) return false; return true; } bool VVL(vector<LLi> vv1, vector<LLi> vv2) { if(vv1.size()!=vv2.size()) return false; rep(i, vv1.size()) if(vv1[i]!=vv2[i]) return false; return true; } //vecotr<LLi>の総和 LLi SML(vector<LLi> smv) { LLi tmp=0; rep(i, smv.size()) tmp+=smv[i]; return tmp; } //n以下の素数を配列に{1, 2, 3, 5, 7, ...} make_prime_list //i, j, flag, sqx, xを使用 void mplist(LLi x){ int flag; for(int i=5;i<=x;i+=2){ flag=0; for(int j=1;j<(int)pri.size();j++){ if(i%pri[j]==0){ flag=1; break; } if(x<pri[j]*pri[j]) break; } if(flag==0) pri.emplace_back(i); } } //nを素因数分解 root_prime_fac //i, tmp, bin, lmt, xを使用 map<LLi, int> rpfac(LLi x){ int sqx=ceil(sqrt(x)); //cout<< "sqx=" << sqx SP << sqx*sqx << endl;// auto bin = lower_bound(all(pri), sqx); int lmt=bin-pri.begin()+1; map<LLi, int> tmp; //cout<< "lmt=" << lmt SP << pri[lmt] SP << pri[lmt]*pri[lmt] <<endl;// if((int)pri.size()<lmt) cout<< "rpfac: pri size is small" <<endl; for(int i=1;i<lmt;i++){ while(x%pri[i]==0){ x/=pri[i]; tmp[pri[i]]++; //cout<< x <<endl; //tmp[0]++;//0番に何個の積でできてるかをメモれる } if(x==1) break; } //if(x!=1) cout<< "prime_fac x=" << x <<endl; return tmp; } //階乗を素因数分解 map<LLi, int> facfac(LLi x){ map<LLi, int> tmp; auto bin = lower_bound(all(pri), x); int lmt=bin-pri.begin()+1; //cout<< "lmt=" << lmt SP << pri[lmt] SP << pri[lmt]*pri[lmt] <<endl;// for(LLi i=1;i<lmt;i++){ int lp=0, di=0; while(pow(pri[i], lp)<x){ lp++; di+=x/pow(pri[i], lp); } if(di>0) tmp[pri[i]]=di; } return tmp; } //約数列挙 //i, j, k, tmp, mul, mを使用 vector<LLi> getfac(map<LLi, int> mp){ vector<LLi> tmp={1}, ad; LLi mul; for (auto p : mp) { mul=1; ad.clear(); LLi key = p.first; int value = p.second; rep(j, value){ mul*=key; rep(k, tmp.size()) ad.push_back(tmp[k]*mul); } rep(j, ad.size()) tmp.push_back(ad[j]); //PV(tmp);// } /*for(int i=1;i<v.size();i++){ if(v[i]==0) continue; mul=1; ad.clear(); rep(j, v[i]){ mul*=pri[i]; rep(k, tmp.size()){ ad.push_back(tmp[k]*mul); } } //PV(tmp); rep(j, ad.size()) tmp.push_back(ad[j]); }*/ sort(all(tmp)); return tmp; } //素因数の積を計算 //i, tmp, vを使用 LLi defac(map<LLi, int> mp){ LLi tmp=1; /*for(int i=1;i<v.size();i++){ if(v[i]!=0) tmp*=pow(pri[i], v[i]); }*/ for (auto p : mp) { LLi key = p.first; int value = p.second; tmp*=pow(key, value); } return tmp; } //素因数の積を計算 //i, tmp, vを使用 LLi defac2(map<LLi, int> mp){ LLi tmp=1; /*for(int i=1;i<v.size();i++){ if(v[i]!=0) tmp*=pow(pri[i], v[i]); }*/ for (auto p : mp) { LLi key = p.first; int value = p.second; tmp*=pow(key, min(1, value)); } return tmp; } //素数判定 is_prime //ub, lb, x, iを使用 bool isp(LLi x){ //if(x==1) return false;//1を素数としないなら有効化 auto ub = upper_bound(all(pri), x); auto lb = lower_bound(all(pri), x); //xがでかいときは素数リストで割ってみる if(lb==pri.end()){ for(int i=1;i<(int)pri.size();i++){ if(x%pri[i]==0) return false; if(x<pri[i]*pri[i]) return true; } //cout<< "isp: pri size is small" <<endl; //priのサイズが足りないときは地道にチェックする for(LLi i=pri[pri.size()-1]+2;i*i<=x;i+=2){ if(x%i==0) return false; } return true; } return ub!=lb; } int main(){ LLi n, m, nl, ml; vector<LLi> v; map<LLi, int> mp, np; cin>> n >> m; mplist(100000);//nまでの素数列挙 //PVL(pri);// np=rpfac(n);//mを√mまで素因数分解 mp=rpfac(m);//mを√mまで素因数分解 nl=defac(np);//mlにmpの総積を代入 ml=defac(mp);//mlにmpの総積を代入 //cout<< "m/ml=" << m/ml SP << isp(m/ml) <<endl;// if(n!=nl) np[n/nl]++;//mpにm/mlを追加(√m以上の素数が約数の場合に必要な処理) if(m!=ml) mp[m/ml]++;//mpにm/mlを追加(√m以上の素数が約数の場合に必要な処理) //mの約数で√m以上の素数は1つしかないのでこれでOK //mp=facfac(n); for (auto pm : mp) { auto mkey = pm.first; auto mvalue = pm.second; //cout<< mkey << "^" << mvalue SP;//mpの内訳を表示 } //cout<< endl;// for (auto p : np) { auto key = p.first; auto value = p.second; //cout<< key << "^" << value SP;//mpの内訳を表示 mp[key]=max(0, mp[key]-value); } cout<< defac2(mp) <<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": [] }
CORRECT
cpp
#include <algorithm> #include <iostream> #include <map> #include <numeric> #include <vector> #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) using namespace std; using lli = long long int; lli gcd(lli x, lli y) { return (y == 0 ? x : gcd(y, x % y)); } lli solve(lli p, lli q) { const lli NMAX = 100008; vector<lli> factor(NMAX, 0); for (lli n = 2; n < NMAX; ++n) { if (factor[n]) { continue; } for (lli k = 2; k * n < NMAX; ++k) { factor[k * n] = n; } } lli ans = 1; for (lli n = 2; q > 1 && n < NMAX; ++n) { if (factor[n] || (q % n != 0)) { continue; } while (q % n == 0) { q /= n; } ans *= n; } ans *= q; return max<lli>(2, ans); } int main() { lli P, Q; cin >> P >> Q; const lli G = gcd(P, Q); P /= G, Q /= G; cout << solve(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": [] }
CORRECT
cpp
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) x.begin(),x.end() const double PI = acos(-1); const ll MOD = 1000000007; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } /////////////////////////////////////////////////////////////// int gcd(int x, int y) { if (x == 0) return y; return gcd(y % x, x); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int p,q; cin >> p >> q; int r = q / gcd(p,q); int s = r; vector<int> A; for (int i = 2; i*i <= r; i++) { if (s % i == 0) { A.emplace_back(i); while (s % i == 0) s /= i; } } if (s != 1) A.emplace_back(s); int ans = 1; rep(i,A.size()) ans *= A[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": [] }
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 <fstream> #include <functional> #include <bitset> using namespace std; #define int long long int const int INF = 1001001001001001LL; const int MOD = 1000000007; int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b); } map<int, int> f(int n){ map<int, int> ret; for(int i = 2; i * i <= n; i++){ while(n % i == 0){ ret[i]++; n /= i; } } if(n > 1) ret[n]++; return ret; } signed main(){ int p, q; cin >> p >> q; int g = gcd(p, q); p /= g; q /= g; map<int, int> m = f(q); int b = 1; for(auto x : m){ b *= x.first; } 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": [] }
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(){ cin.tie(0); ios::sync_with_stdio(false); int p,q,r=1; cin >> p >> q; q/=gcd(p,q); for (int i=2;i*i<=q;++i){ if (q%i==0){ r*=i; while(q%i==0) q/=i; } } cout << q*r << '\n'; }
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": [] }
CORRECT
cpp
#include <iostream> #include<cstdlib> #include<queue> #include<set> #include<vector> #include<string> #include<algorithm> #include<sstream> #include<cmath> #include<stack> #include<map> #include<cstdio> using namespace std; #define rep(i,a) for(int i=0;i<a;i++) #define mp make_pair #define pb push_back #define P pair<int,int> #define ll __int64 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; } } } int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } int main(){ eratosu(); cin>>p>>q; for(int i=0;i<primes.size();i++){ int now=primes[i]; while(q%now==0&&p%now==0)q/=now,p/=now; } 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(now>sqrt(qq))break; } 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MP make_pair #define PB push_back #define MOD 1000000007 #define INF (1LL<<30) #define LLINF (1LL<<60) #define PI 3.14159265359 #define EPS 1e-12 #define int ll int gcd(int a, int b) { return b != 0 ? gcd(b, a%b) : a; } signed main(void) { int p, q; cin >> p >> q; int r = gcd(p, q); //cout << r << endl; p /= r; q /= r; set<int> s; ll a = 2; while(q >= a*a) { if(q % a == 0) { s.insert(a); q /= a; } else { a++; } } s.insert(q); ll ret = 1; for(int i: s) ret *= i; cout << ret << 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int p, q; cin >> p >> q; p = gcd(p, q); q /= p; set<int> s; for (int i = 2; i <= q;) { if (i * i > q) { i = q; } if (q % i == 0) { q /= i; s.insert(i); } else { i++; } } int r = 1; for (auto it = begin(s); it != end(s); it++) { r *= *it; } 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": [] }
CORRECT
cpp
#include <iostream> #include <vector> using namespace std; using ll = long long; ll gcd(const ll a, const ll b) { if (a == 0 or b == 0) { return (a == 0) ? b : a; } if (a > b) { return gcd(b, a); } else { return gcd(b % a, a); } } constexpr int SQRT = 100000; bool isprime[SQRT]; int main() { ll p, q; cin >> p >> q; const ll g = gcd(p, q); q /= g; fill(isprime, isprime + SQRT, true); for (ll i = 2; i < SQRT; i++) { if (isprime[i]) { for (ll j = 2; i * j < SQRT; j++) { isprime[i * j] = false; } } } vector<ll> prime; for (ll i = 2; i < SQRT; i++) { if (isprime[i]) { prime.push_back(i); } } vector<ll> factor; for (ll p : prime) { if (q % p == 0) { factor.push_back(p); } while (q % p == 0) { q /= p; } } if (q > 1) { factor.push_back(q); } ll prod = 1; for (const ll f : factor) { prod *= f; } cout << prod << 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define printV(v) for(auto x : v){cout << x << " ";} cout << endl #define printVS(vs) for(auto x : vs){cout << x << endl;} #define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;} #define printP(p) cout << p.first << " " << p.second << endl #define printVP(vp) for(auto p : vp) printP(p); typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> TUPLE; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<Pii> vp; typedef vector<vector<int>> Graph; const int inf = 1e9; const int mod = 1e9 + 7; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } map<int, int> primeFactorize(int n) { map<int, int> res; for (int i = 2; i * i <= n; ++i) { while (n % i == 0) { ++res[i]; n /= i; } } if (n > 1) ++res[n]; return res; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int p, q; cin >> p >> q; int g = gcd(p, q); p /= g; q /= g; auto mp = primeFactorize(q); int x = 1; for (auto p : mp) { x = lcm(x, p.first); } cout << x << 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": [] }
CORRECT
cpp
/* -*- coding: utf-8 -*- * * 2706.cc: Let's Solve Geometric Problems */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_P = 32000; /* typedef */ typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pii> vpii; /* global variables */ bool primes[MAX_P + 1]; /* subroutines */ int gen_primes(int maxp, vi &pnums) { memset(primes, true, sizeof(primes)); primes[0] = primes[1] = false; int p; for (p = 2; p * p <= maxp; p++) if (primes[p]) { pnums.push_back(p); for (int q = p * p; q <= maxp; q += p) primes[q] = false; } for (; p <= maxp; p++) if (primes[p]) pnums.push_back(p); return (int)pnums.size(); } bool prime_decomp(int n, vi &pnums, vpii& pds) { pds.clear(); int pn = pnums.size(); for (int i = 0; i < pn; i++) { int pi = pnums[i]; if (pi * pi > n) { if (n > 1) pds.push_back(pii(n, 1)); return true; } if (n % pi == 0) { int fi = 0; while (n % pi == 0) n /= pi, fi++; pds.push_back(pii(pi, fi)); } } return false; } int gcd(int m, int n) { // m >= n > 0 while (n > 0) { int r = m % n; m = n; n = r; } return m; } int powi(int a, int b) { int p = 1; while (b) { if (b & 1) p *= a; a *= a; b >>= 1; } return p; } /* main */ int main() { vi pnums; int pn = gen_primes(MAX_P, pnums); //printf("pn=%d\n", pn); int p, q; scanf("%d%d", &p, &q); int g = gcd(q, p); //printf("gcd(%d,%d)=%d\n", p, q, g); int n = q / g; vpii pds; prime_decomp(n, pnums, pds); /* printf("%d = ", n); for (int i = 0; i < pds.size(); i++) { if (i) putchar('*'); printf("%d^%d", pds[i].first, pds[i].second); } putchar('\n'); */ int m = 1; for (int i = 0; i < pds.size(); i++) m *= pds[i].first; printf("%d\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": [] }
CORRECT
cpp
#include<iostream> using namespace std; int p,q,ans=1,j; int so(int n){ for(int i=2;i*i<=n;i++)if(n%i==0)return 1; return 0; } int main(){ cin>>p>>q; if(so(q)){ for(int i=2;q>=i;i++){ for(j=0;q%i==0;j++){ q/=i; if(p%i==0)p/=i,j--; } if(j==0)continue; /*if(p%(i*j)==0)p/=(i*j); else*/ ans*=i; } cout<<ans<<endl; }else 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": [] }
CORRECT
cpp
#include "bits/stdc++.h" #define REP(i,n) for(ll i=0;i<n;++i) #define RREP(i,n) for(ll i=n-1;i>=0;--i) #define FOR(i,m,n) for(ll i=m;i<n;++i) #define RFOR(i,m,n) for(ll i=n-1;i>=m;--i) #define ALL(v) (v).begin(),(v).end() #define PB(a) push_back(a) #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()); #define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; } #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 const int dx[8] = { 1,1,0,-1,-1,-1,0,1 }; const int dy[8] = { 0,1,1,1,0,-1,-1,-1 }; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll max(ll a, int b) { return max(a, ll(b)); } ll max(int a, ll b) { return max(ll(a), b); } ll min(ll a, int b) { return min(a, ll(b)); } ll min(int a, ll b) { return min(ll(a), b); } ///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)/// int gcd(int a, int b) { if (!b)return a; return gcd(b, a%b); } int fact(int n) { int res = 1, i = 2; int p = n; while (i*i<=p) { if (n % i == 0) { res *= i; while (n%i == 0)n /= i; if(n!=i*i)res *= fact(n); break; } ++i; } if (res == 1)return n; else return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int p, q; cin >> p >> q; int c = gcd(p, q); p /= c; q /= c; int i = 2; cout << fact(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": [] }
CORRECT
cpp
#include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> #include <utility> #include <functional> #include <sstream> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <climits> #include <fstream> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); } typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i,n) FOR(i,0,(n)-1) const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX / 10; const int MOD = 1000000007; int gcd(int x, int y) { if (x < y) { swap(x, y); } if (y == 0) { return x; } return gcd(y, x%y); } int main() { int p, q; cin >> p >> q; int m = sqrt(q) + 1; vi prime(m+1, 1); prime[0] = prime[1] = 0; FOR(i, 2, m) { if (prime[i]) { for (int j = i*i; j <= m; j += i) { prime[j] = 0; } } } int ans = 1; q /= gcd(p, q); FOR(i, 2, m) { if ((prime[i] == 1) && (q%i == 0)) { ans *= i; while (q%i == 0) { q /= i; } } } if (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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define each(i,a) for (auto&& i : a) #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++) #define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) #define pb push_back #define all(a) (a).begin(),(a).end() #define chmin(x,v) x = min(x, v) #define chmax(x,v) x = max(x, v) const ll 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) { each(x,vec) is >> x; return is; } template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i,vec.size()) { if (i) os << " "; os << vec[i]; } return os; } template<typename T> ostream& operator<<(ostream& os, const vector< vector<T> >& vec) { rep(i,vec.size()) { if (i) os << endl; os << vec[i]; } return os; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); } ll solve(ll n) { vector<ll> v; for (ll i = 2; i*i <= n; ++i) { if (n % i == 0) { while (n % i == 0) n /= i; v.pb(i); } } v.pb(n); ll res = 1; each(x, v) res *= x; return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll p, q; cin >> p >> q; cout << max(2LL, solve(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": [] }
CORRECT
cpp
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <climits> #include <vector> #include <map> #include <set> #include <list> #include <stack> #include <queue> #include <algorithm> #include <iostream> #include <string> #define REP(i,n) for(long long i=0;i<n;++i) #define REPR(i,n) for(long long i=n;i>=0;--i) #define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr) #define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr) #define FOR(i,a,b) for(long long i=a;i<b;++i) #define SORT(v,n) sort(v, v+n) #define SORTV(v) sort(v.begin(), v.end()) #define ALL(v) v.begin(),v.end() #define llong long long #define INF 999999999 #define SUR 1000000007 #define pb push_back #define pf push_front #define MP make_pair #define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}} int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; using namespace std; typedef pair<int,int> pii; int main(){ llong p, q; cin >> p >> q; llong a = q, b = p; llong r = a % b; while(r != 0){ a = b; b = r; r = a % b; } p /= b; q /= b; map<llong, llong> mp; for(int i = 2; i * i <= q; ++i){ if(q % i == 0){ mp[i]++; while(q % i == 0) q /= i; } } if(q != 1){ mp[q]++; } llong ans = 1; REPI(itr, mp){ 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": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <set> using namespace std; typedef long long ll; const ll INF = 1LL << 50; int solve(); ll gcd(ll p, ll q) { if (q == 0) { return p; } return gcd(q, p%q); } int main(void) { while (solve()) {} return 0; } int solve() { ll p, q, g; cin >> p >> q; g = gcd(max(p, q), min(p, q)); // 約分 p = p / g; q = q / g; // 答えはqの素因数をすべて掛け合わせたもの // sqrt{q}までの素数を調べる const ll M = (1e+9) + 1; const ll N = sqrt(M) + 1; ll ans; //cout << M << " " << N << endl; // エラトステネスの篩 vector<ll> primes; primes.reserve(5000); vector< bool > isPrime(M, true); isPrime[0] = false; isPrime[1] = false; for (ll i = 2; i < N; i++) { if (isPrime[i] == false) { continue; } // 合成数なら primes.push_back(i); for (ll j = i; i * j < N; j++) { isPrime[i*j] = false; } } ll qc = q; set<ll> facts; for (auto p : primes) { if( qc % p == 0 ) { while(qc % p == 0) qc /= p; if( qc % p > 0 ) { facts.insert(p); } } } ans = qc; for( auto itr = facts.begin(); itr != facts.end(); ++itr ){ ans *= (*itr); } 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second #define FOR(i, a, b) for(int i=(a);i<(b);i++) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for(int i=(a);i>=(b);i--) #define RREP(i, n) RFOR(i, n, 0) #define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((int)(x).size()) typedef long long int ll; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; const double eps = 1e-10; const int MOD = 1000000007; const int INF = 1000000000; const ll LINF = 1 << 30; template<typename T> void printv(vector<T> const& s) { REP(i, SZ(s)) { cout << s[i] << " "; } cout << endl; } int gcd(int a, int b) { if(b == 0) return a; else return gcd(b, a%b); } int main () { cin.tie(0); cout << setprecision(10); int p, q; cin >> p >> q; int g = gcd(p, q); p /= g; q /= g; int ans = 1; int tmpq = q; for(int i=2;i*i<=tmpq;i++) { if(q % i == 0) { ans *= i; } while(q % i == 0) { q /= i; } } if(q != 1) ans *= q; 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": [] }
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*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": [] }
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); int ret=1; for(int i=2;a>1;i++){ if(a%i!=0) continue; ret*=i; while(a%i==0) a/=i; } out.println(ret); } 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": [] }
CORRECT
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { // TODO 自動生成されたメソッド・スタブ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] tmpArray = br.readLine().split(" "); int p = Integer.parseInt(tmpArray[0]); int q = Integer.parseInt(tmpArray[1]); int g = gcd(p, q); q /= g; //qを構成する約数を調べる int result = 1; for(int i = 2; i <= q; i++){ boolean divided = false; while(q % i == 0){ divided = true; q /= i; } if(divided){ result *= i; } } System.out.println(result); } static int gcd(int a, int b){ int tmp; while (a % b != 0) { tmp = b; b = a % b; a = tmp; } return 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": [] }
CORRECT
cpp
#include <algorithm> #include <iostream> #include <vector> #include <map> using namespace std; inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } map<long long, int> prime_factorize(long long n) { map<long long, int> res; for (long long p = 2; p * p <= n; ++p) { while (n % p == 0) { ++res[p]; n /= p; } } if (n != 1) res[n] = 1; return res; } int main() { long long p, q; cin >> p >> q; long long g = gcd(p, q); q /= g; long long ans = 1; for (auto &p: prime_factorize(q)) ans *= p.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": [] }
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; 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": [] }
CORRECT
cpp
#include<iostream> #include<algorithm> 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; q/=COU(p,q); for(int i=2;i*i<=q;i++){ while(!(q%(i*i)))q/=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": [] }
CORRECT
python3
def gcd(a,b): while b:a,b=b,a%b return a if __name__=="__main__": a,b=map(int,input().split()) b//=gcd(a,b) a,c=2,1 while a**2<=b: if b%a==0: c*=a while b%a==0: b//=a a+=1 print(c if b==1 else c*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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { return b ? GCD(b, a%b) : a; } int main() { int p, q, n, res = 1; cin >> p >> q; n = q / GCD(p, q); for (int i = 2; i < sqrt(n) + 2; i++) { if (n % i == 0) { res *= i; while (n % i == 0) { n /= i; } } } res *= n; if (res == 1) res = 2; cout << res << 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": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(a) (a).begin(),(a).end() using ll = long long; ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} int main(){ int p, q; cin>>p>>q; int g = gcd(q, p); q /= g; int res = 1; for (int i = 2; i*i <= q; ++i) { if (q % i == 0) { res *= i; while (q % i == 0) { q /= i; } } } if (q > 1) res *= q; if (res > 1) { cout << res << endl; } else { cout << 2 << 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": [] }
CORRECT
java
import java.util.ArrayList; import java.util.Scanner; public class Main { static int[][] map; static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }; static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; static int ans; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int p = sc.nextInt(); int q = sc.nextInt(); q = q / gcd(p, q); ans = 1; int idx = 2; boolean[] divided = new boolean[q + 1]; if (isPrime(q)) { System.out.println(q); } else { while (q != 1) { if (!divided[idx] && q % idx == 0) { ans *= idx; while (q % idx == 0) { q /= idx; } for (int i = idx; i * i <= q; i += idx) { divided[i] = true; } } idx++; } System.out.println(ans); } } // longの素数判定 static boolean isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; int i = 3; while (i <= Math.sqrt(n)) { if (n % i == 0) return false; else i += 2; } return true; } // BFS用に二つの配列を足し算する static int[] addArrayElms(int[] a, int[] b) { int[] c = new int[a.length]; for (int i = 0; i < a.length; i++) { c[i] = a[i] + b[i]; } return c; } // //二分探索 // k <= num となる最小の配列要素kのインデックスを返す static private int binarySearch(long num, long[] orderedArray) { int lowerBorder = -1; int upperBorder = orderedArray.length; int mid; while (upperBorder - lowerBorder > 1) { mid = (upperBorder + lowerBorder) / 2; if (orderedArray[mid] <= num) { lowerBorder = mid; } else { upperBorder = mid; } } return lowerBorder; } // 二分探索 // k <= num となる最小のList要素kのインデックスを返す static private int binarySearch(long num, ArrayList<Long> orderedList) { int lowerBorder = -1; int upperBorder = orderedList.size(); int mid; while (upperBorder - lowerBorder > 1) { mid = (upperBorder + lowerBorder) / 2; if (orderedList.get(mid) <= num) { lowerBorder = mid; } else { upperBorder = mid; } } return lowerBorder; } // aとbの最小公倍数を求める public static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public static long gcd(long a, long b) { return b == 0 ? a : 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": [] }
CORRECT
cpp
#include<iostream> #include<algorithm> using namespace std; int main() { int p, q, mi, ans, temp; 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); } } ans = 1; for (int i = 2; i * i <= q; i++) { if (q%i != 0) continue; int k = 1; if (i != 2){ for (int j = 3; j * j<= i; j++) { if (i%j == 0) { k = 0; break; } } } if (k == 1) ans *= i; while (q%i == 0) { q /= i; } } 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": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int gcd(int p,int q){ return q==0 ? p : gcd(q,p%q); } int main(){ int p,q; while(cin>>p>>q,p){ int g=gcd(p,q); p/=g; q/=g; long long int res=1; for(int i=2;i<1e5;i++){ if(q%i==0){ res*=i; while(q%i==0) q/=i; } } res*=q; cout<<res<<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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define REP(i,n) for (int i=0;i<(n);i++) 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 r=gcd(q,p); p/=r;q/=r; int ans=1; for(int i=2;i*i<=q;i++){ if(q%i!=0)continue; ans*=i; while(q%i==0)q/=i; } ans*=q; 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": [] }
CORRECT
python3
import math # import numpy as np # Pythonのみ! # from operator import xor # import re # from scipy.sparse.csgraph import connected_components # Pythonのみ! # ↑cf. https://note.nkmk.me/python-scipy-connected-components/ # from scipy.sparse import csr_matrix # import string import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): p,q=map(int,input().split()) g=math.gcd(p,q) p//=g q//=g # cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f def make_prime_list_2(num): if num < 2: return [] # 0のものは素数じゃないとする prime_list = [i for i in range(num + 1)] prime_list[1] = 0 # 1は素数ではない num_sqrt = math.sqrt(num) for prime in prime_list: if prime == 0: continue if prime > num_sqrt: break for non_prime in range(2 * prime, num, prime): prime_list[non_prime] = 0 return [prime for prime in prime_list if prime != 0] def prime_factorization_2(num): """numの素因数分解 素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す""" if num <= 1: # 例えば1を食ったときの対処の仕方は問題によって違うと思うのでそのつど考える。 # cf. https://atcoder.jp/contests/abc110/submissions/12688244 return False else: num_sqrt = math.floor(math.sqrt(num)) prime_list = make_prime_list_2(num_sqrt) dict_counter = {} # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして # cf. https://atcoder.jp/contests/arc034/submissions/12251452 for prime in prime_list: while num % prime == 0: if prime in dict_counter: dict_counter[prime] += 1 else: dict_counter[prime] = 1 num //= prime if num != 1: if num in dict_counter: dict_counter[num] += 1 else: dict_counter[num] = 1 return dict_counter d=prime_factorization_2(q) ans=1 for k in d.keys(): ans*=k print(ans) resolve()
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": [] }
CORRECT
cpp
#include<stdio.h> #include<math.h> #include<iostream> #include<string> #include<algorithm> #include<math.h> #include<set> #include<map> #include<vector> #include<stack> #include<queue> #include<cmath> #include<numeric> using namespace std; int yaku(int n,int m){ if(n%m==0){ return m; } return yaku(m,n%m); } int main(){ int n,m; cin>>n>>m; m/=yaku(n,m); int ans=1; for(int i=2;i*i<=m;i++){ if(m%i==0){ ans*=i; while(m%i==0){ m/=i; } } } ans*=m; 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": [] }
CORRECT
cpp
#include<bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define vi vector<ll> #define vvi vector<vi> #define BITLE(n) (1LL<<((ll)n)) #define SHIFT_LEFT(n) (1LL<<((ll)n)) #define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1)) #define ALL(a) (a).begin(),(a).end() #define EPS 1e-15 using namespace std; ll gcd(ll a,ll b){ ll r = a%b; while(r>0){ a = b;b = r; r =a%b; } return b; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll p,q;cin>>p>>q; ll g = gcd(p,q); ll ans = 1; q/=g; ll loop = q; for(ll i = 2;i <= sqrt(loop);i++){ if(q % i == 0){ ans *= i; while(q%i == 0){ q/=i; } } } cout<<ans*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": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; const int INF = 1e9; using ll = long long; void bunkai(vector<ll> &a,ll x){ ll temp=x; for(ll i=2;i*i<=x;i++){ if(temp%i==0){ a.push_back(i); while(temp%i==0){ temp/=i; } } } a.push_back(temp); return; } ll gcd(ll x,ll y){ if(x%y==0){ return y; }else{ return gcd(y,x%y); } } int main(){ ll p,q; cin>>p>>q; ll a=gcd(q,p); p/=a; q/=a; //cout<<"p="<<p<<"q="<<q<<endl; vector<ll> soinsu; bunkai(soinsu,q); ll ans=1; for(ll i=0;i<soinsu.size();i++){ ans*=soinsu[i]; //cout<<"ans="<<ans<<endl; } 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": [] }
CORRECT
cpp
#include <stdio.h> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> typedef long long int ll; #define BIG_NUM 2000000000 using namespace std; int calc(int x,int y){ if(y == 0){ return x; }else{ return calc(y,x%y); } } int main(){ int p,q,common,limit; scanf("%d %d",&p,&q); common = calc(p,q); p /= common; q /= common; limit = sqrt(q); int ans = 1; for(int i = 2; i <= limit; i++){ if(q%i == 0){ ans *= i; while(q % i == 0)q /= i; } } ans *= q; printf("%d\n",ans); 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<29; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-11; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; ll gcd(ll a,ll b){ if(!b) return a; return gcd(b,a%b); } map<int,int> Prime_Factor(int n){ map<int,int> m; for(int i=2;i*i<=n;i++){ while(n%i==0){ m[i]++; n/=i; } } if(n!=1) m[n]++; return m; } int main(){ ll n,m; cin>>n>>m; m/=gcd(n,m); auto mp=Prime_Factor(m); ll t=1; for(auto p:mp) t*=p.first; cout<<t<<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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int p, q; int gcd(int x, int y){ if(x % y == 0) return y; return gcd(y, x % y); } bool prime(int x){ bool f = true; for(int i=2; i*i<=x; ++i) if(x % i == 0) f = false; return f; } int main(){ // cin.tie(0); // ios::sync_with_stdio(false); cin >> p >> q; int g = gcd(p, q); q /= g; // cout << p / g << " " << q << "\n"; vector<int> a; if(prime(q)){ cout << q << "\n"; return 0; } for(int i=2; i<=q; ++i){ if(q % i == 0){ int t = 1; q /= i; while(q % i == 0){ ++t; q /= i; } a.push_back(i); } } int ans = 1; for(int i=0; i<a.size(); ++i) ans *= a[i]; cout << ans << "\n"; }
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": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define REP(i,j) for(int i = 0; i < j; i++) int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main(){ int p1,q; cin >> p1 >> q; int t = gcd(p1,q); q /= t; vector<int> pl; pl.push_back(2); pl.push_back(3); for(int i = 5; i*i < 1e9; i+=2){ bool f = true; for(int j = 3; j*j <= i; j+=2){ if(i % j == 0)f = false; } if(f) pl.push_back(i); } for(int i = 0; i < pl.size(); i++){ while(q%(pl[i]*pl[i]) == 0){ q /= pl[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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int p, q; int main() { cin >> p >> q; vector<int> A = {}; for (int i = 2; i * i <= q; i++) { if(q % i == 0) { A.push_back(i); A.push_back(q / i); } } for (auto i : A) { while (p % i == 0 and q % i == 0) { p /= i; q /= i; } } vector<int> pr ={}; for (int i = 2; i * i <= q; i++) { if (q % i == 0) pr.push_back(i); while (q % i == 0) q /= i; } for (auto pp : pr) { q *= pp; } 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); i++) #define repp(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl #define CNO cout<<"No"<<endl #define CFS cin.tie(0);ios::sync_with_stdio(false) typedef long long LL; typedef long double LD; LL gcd(LL x, LL y){ while(x%y){ LL tmp = x%y; x=y; y=tmp; } return y; } int main(){ LL p,q; cin >> p >> q; p%=q; q/=gcd(p,q); LL ans=1; repp(i,2,sqrt(q)+1){ if(q%i==0){ ans*=i; while(q%i==0) q/=i; } } if(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": [] }
CORRECT
cpp
#include<iostream> using namespace std; int p, q; int gcd(int a, int b) { if (b == 0)return a; return gcd(b, a%b); } int main() { cin >> p >> q; int res = 1; int r = gcd(p, q); q /= r; for (int i = 2; i*i <= q; i++) { if (q%i == 0) { res *= i; while (q%i == 0)q /= i; } } if (q >= 2)res *= q; cout << res << 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": [] }
CORRECT
cpp
#include<iostream> using namespace std; int p,q,ans=1,j; int so(int n){ for(int i=2;i*i<=n;i++)if(n%i==0)return 1; return 0; } int main(){ cin>>p>>q; if(so(q)){ for(int i=2;q>=i;i++){ for(j=0;q%i==0;j++){ q/=i; if(p%i==0)p/=i,j--; } if(j==0)continue; ans*=i; } cout<<ans<<endl; }else 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": [] }
CORRECT
cpp
#include<bits/stdc++.h> const int MOD=1000000007; const int INF=1000000000; using namespace std; typedef long long ll; typedef vector<int> vi; const double eps=1e-9; const int inf=1e9; typedef pair<int,int> P; struct Point { double x,y; Point(){x=0;y=0;} Point(double d_x,double d_y){x=d_x,y=d_y;} double operator*(Point obj){return obj.x*x+obj.y*y;} double operator%(Point obj){return obj.y*x-obj.x*y;} Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;} Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;} Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;} Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;} Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;} Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;} Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;} Point operator/=(double b){x=x/b;y=y/b;return *this;} Point operator*=(double b){x=x*b;y=y*b;return *this;} double size(){return hypot(x,y);} Point unit(){return Point(x/size(),y/size());} Point normal(){return Point(y,-x);} double atan(){return atan2(y,x);} }; bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;} bool operator>(Point a,Point b){return b<a;} bool operator<=(Point a,Point b){return !(b<a);} bool operator>=(Point a,Point b){return !(a<b);} bool operator==(Point a,Point b){return (a-b).size()<eps;} bool operator!=(Point a,Point b){return !(a==b);} bool equal(double a,double b){return abs(a-b)<eps;} double cross(Point a,Point b){return a%b;} double dot(Point a,Point b){return a*b;} int ccw(Point a,Point b,Point c) { b=b-a; c=c-a; if(b%c>0) return +1; else if(b%c<0)return -1; else if(b*c<0) return +2; else if(b.size()<c.size()) return -2; else return 0; } int gcd(int a,int b) { if(b>a) { swap(a,b); gcd(a,b); } if(b==0) return a; else if(b==1) return b; int p=a/b; a-=p*b; return gcd(b,a); } int main(int argc,char const* argv[]) { int p,q,k; cin >>p >> q; k=gcd(p,q); p/=k; q/=k; int q_=q; vector<P> ans; for(int i=2;i<=sqrt(q);i++) { if(q_%i==0) { P pa=make_pair(i,1); q_ /=i; while(q_%i ==0) { pa.second++; q_ /=i; } ans.push_back(pa); } } if(q_ > 1) ans.push_back(P(q_,1)); int a=1; for(int i=0;i<(int) ans.size();i++) { a*=ans[i].first; } 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": [] }
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 /= GCD(p, q); map<int, int> mpa; for(int i = 2; i * i <= q; i++){ while(q % i == 0){ mpa[i]++; q /= i; } } if(q != 1) mpa[q]++; map<int, int>::iterator it; int ans = 1; for(it = mpa.begin(); it != mpa.end(); it++){ ans *= it->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": [] }
CORRECT
cpp
#include <iostream> #include <queue> #include <vector> #include <algorithm> #include <set> #include <cmath> #include <tuple> #include <cstring> #include <map> #include <iomanip> #include <ctime> #include <complex> #include <cassert> #include <climits> using namespace std; typedef long long ll; typedef unsigned long long ull; #define _ << " " << #define all(X) (X).begin(), (X).end() #define len(X) (X).size() #define Pii pair<int, int> #define Pll pair<ll, ll> #define Tiii tuple<int, int, int> #define Tlll tuple<ll, ll, ll> ll gcd(ll a, ll b) { if (a < b) swap(a, b); ll r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } vector<Pll> PF(ll n) { vector<Pll> fs; ll base = n; for (ll i = 2; i * i <= base; i++) { if (base % i == 0) { int cnt = 0; while (base % i == 0) { base /= i; cnt++; } fs.emplace_back(i, cnt); } } if (base > 1) fs.emplace_back(base, 1); return fs; } int main() { int p, q; cin >> p >> q; int g = gcd(p, q); vector<Pll> fs = PF(q / g); int ans = 1; for (auto &i : fs) ans *= 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": [] }
CORRECT
cpp
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<cmath> #include<cstring> #include<queue> #include<cstdio> #include<sstream> #include<iomanip> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #define mp make_pair #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) using namespace std; //kaewasuretyuui typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef pair<int,pii> pip; typedef vector<pip>vip; const double PI=acos(-1); const double EPS=1e-8; const int inf=1<<30; int gcd(int a,int b){ return (b==0?a:gcd(b,a%b)); } int main(){ int a,b; cin>>a>>b; b/=gcd(a,b); int out=1; for(int t=2;t*t<=b;t++)if(b%t==0){ out*=t; while(b%t==0)b/=t; } cout<<out*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": [] }
CORRECT
cpp
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; ll gcd(ll x, ll y) { ll r; if (x < y) { swap(x, y); } while (y > 0) { r = x % y; x = y; y = r; } return x; } map<ll, ll> prime_factor(ll a) { map<ll, ll> ret; for (ll i = 2; i * i <= a; i++) { while (a % i == 0 && a != 0) { ret[i]++; a /= i; } } if (a != 1) { ret[a]++; } return ret; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll p, q; scanf("%lld %lld", &p, &q); ll g = gcd(p, q); p /= g; q /= g; map<ll, ll> mp1 = prime_factor(p); map<ll, ll> mp2 = prime_factor(q); vector<ll> v; //for (auto p : mp1) v.push_back(p.first); for (auto p: mp2) v.push_back(p.first); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); ll res = 1; for (auto e : v) res *= e; cout << res << 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": [] }
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; int g = gcd(p, q); p /= g; q /= g; int ans = 1; for (int i = 2; i * i <= q; i++){ if (q % i == 0){ ans *= i; while (q % i == 0){ q /= i; } } } if (q != 1){ ans *= q; } 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define ll long long 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; q /= gcd(p, q); for (int i = 2; i * i <= q; i++) { while (q % (i * i) == 0) q /= 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": [] }
CORRECT
cpp
#include <iostream> 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); long long int x = 1; for(int i = 2; i * i <= q; i++){ if(q % i == 0){ x *= i; while(q % i == 0) q /= i; } } cout << x * 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<int, lint> pil; typedef pair<lint, lint> pll; template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;} template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;} template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;} template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;} constexpr lint mod = 1e9+7; constexpr lint INF = mod*mod; constexpr int MAX = 100010; lint gcd(lint p, lint q){ if(p < q) swap(p, q); while(q){ lint r = p % q; p = q; q = r; } return p; } int main(){ lint p, q; scanf("%lld%lld", &p, &q); lint g = gcd(p, q); p /= g; q /= g; lint ans = 1; for(lint i=2; i*i<=q; ++i){ if(q%i == 0){ ans *= i; while(q%i == 0) q /= i; } } if(q > 1) ans *= q; printf("%lld\n", 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #include<iostream> #include<cstdio> #include<vector> #include<queue> #include<map> #include<cstring> #include<string> #include <math.h> #include<algorithm> // #include <boost/multiprecision/cpp_int.hpp> #include<functional> #define int long long #define inf 1000000007 #define pa pair<int,int> #define ll long long #define pal pair<double,pa> #define ppa pair<pa,int> #define ppap pair<int,pa> #define ssa pair<string,int> #define mp make_pair #define pb push_back #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b))<EPS) using namespace std; //priority_queue<int, vector<int>, greater<int> > que; 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)<EPS && fabs(y-p.y)<EPS; } }; typedef Point Vector; struct Segment{ Point p1,p2; }; double hen(Vector a){ if(fabs(a.x)<EPS && a.y>0) return acos(0); else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0); else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0); else if(fabs(a.y)<EPS && 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( int i ) { ostringstream s ; s << i ; return s.str() ; } int gcd(int v,int 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(Vector a,Vector b){ return a.x*b.x+a.y*b.y; } double cross(Vector a,Vector 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); } /*} int pr[100010]; //int inv[100010]; int beki(int wa,int rr){ if(rr==0) return 1ll; if(rr==1) return wa; if(rr%2==1) return (beki(wa,rr-1)*wa)%inf; int zx=beki(wa,rr/2); return (zx*zx)%inf; } void gya(){ pr[0]=1; for(int i=1;i<100010;i++){ pr[i]=(pr[i-1]*i)%inf; } for(int i=0;i<100010;i++) inv[i]=beki(pr[i],inf-2); } */ //----------------kokomade tenpure------------ bool b[100020]={0}; signed main(){ b[1]=1; for(int i=2;i<100020;i++){ if(b[i]==1) continue; int d=2*i; while(d<100020){ b[d]=1; d+=i; } } int n,m; cin>>n>>m; m=m/gcd(n,m); vector<int> ve; for(int i=2;i<100020;i++){ if(b[i]==1) continue; int ko=0; while(1){ if(m%i==0){ m/=i; ko++; if(ko==1) ve.pb(i); } else break; } } if(m>1) ve.pb(m); int ans=1; for(int i=0;i<ve.size();i++) ans*=ve[i]; cout<<ans<<endl; /* while(1){ cin>>n>>m; if(n==0) 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": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <algorithm> using namespace std; int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } bool isPrime[100000]; typedef pair<int,int> P; int main(){ int p,q; cin>>p>>q; int d = gcd(p,q); p/=d; q/=d; // cout<<p<<' '<<q<<endl; fill(isPrime,isPrime+100000,true); isPrime[0]=isPrime[1]=false; for(int i=0;i<100000;i++){ if(isPrime[i])for(int k=2;k*i<100000;k++) isPrime[i*k]=false; } int ans=1; vector<P> V; for(int i=0;i<100000;i++){ if(!isPrime[i]) continue; if(q%i==0){ ans*=i; while(q%i==0) q/=i; } } ans*=q; 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": [] }
CORRECT
cpp
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" using namespace std; const long long int MOD = 1000000007; long long int N, M, K, H, W, L, R; int gcd(int a, int b) { if (a < b)swap(a, b); while (b) { a %= b; swap(a, b); } return a; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; M /= gcd(N, M); for (int i = 2; i*i <= M; i++) { long long int box = i; long long int div = 1; while (box < M) { box *= i; if (M%box == 0)div *= i; } M /= div; } cout << 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": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> P; const int M = 1000000007; int gcd(int a, int b) { while (b > 0) { int t = a % b; a = b; b = t; } return a; } int main() { int p, q; cin >> p >> q; int g = gcd(p, q); q /= g; int ans = 1; for (int i = 2; i * i <= q; ++i) { if (q % i == 0) { ans *= i; while (q % i == 0) q /= i; } } ans *= q; cout << max(ans, 2) << "\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": [] }
CORRECT
python3
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = LS() return l sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): while 1: n,m = LI() if n == 0 and m == 0: break v = [[] for i in range(n)] for i in range(m): a,b = LI() a -= 1 b -= 1 v[a].append(b) v[b].append(a) bfs_map = [1 for i in range(n)] bfs_map[0] = 0 f = [0 for i in range(n)] q = deque() q.append(0) fl = 1 while q: if not fl:break x = q.popleft() for y in v[x]: if bfs_map[y]: bfs_map[y] = 0 f[y] = (1-f[x]) q.append(y) else: if f[y] == f[x]: print(0) fl = 0 break if fl: ans = [] k = sum(f) if k%2 == 0: ans.append(k//2) k = len(f)-sum(f) if k%2 == 0: ans.append(k//2) ans = list(set(ans)) ans.sort() print(len(ans)) for i in ans: print(i) return #B def B(): def gcd(a,b): if a == 0: return b return gcd(b%a, a) def factorize(n): if n < 4: return {n:1} i = 2 d = defaultdict(int) m = n while i**2 <= n: if m%i == 0: while m%i == 0: m//=i d[i] += 1 i += 1 d[m] += 1 return d p,q = LI() g = gcd(p,q) ans = q//g if ans == 1: print(1) else: d = factorize(ans) ans = 1 for i in d.keys(): ans *= i print(ans) return #C def C(): return #D def D(): return #E def E(): return #F def F(): return #G def G(): return #H def H(): return #I def I_(): return #J def J(): return #Solve if __name__ == "__main__": 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": [] }
CORRECT
cpp
#include <iostream> using namespace std; int gcd(int p,int q){ int r=q%p; while(r>0){ q=p; p=r; r=q%p; } return p; } int divide(int b,int i){ while(b%(i*i)==0){ b/=i; } return b; } int main(){ int p,q; cin>>p>>q; int b=q/gcd(p,q); for(int i=2;i*i<=b;i++) b=divide(b,i); 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": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) int main(){ int p,q; method(gcd,int,int a,int b){ while(b){ a %= b; swap(a,b); } return a; }; method(func,int,int x){ int res = 1; for(int i=2;i*i<=x;++i){ bool flag = false; while(x%i==0){ x /= i; flag = true; } if(flag)res *= i; } res *= x; return res; }; cin >> p >> q; cout << func(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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i) int ext_gcd(int a, int b, int &x, int &y){ if(b == 0){ x = 1; y = 0; return a; } int q = a / b; int g = ext_gcd(b, a-q*b, x, y); int z = x - q * y; x = y; y = z; return g; } map<int,int> pf(int n){ map<int,int> res; FOR(i,2,sqrt(n)+1){ if(n == 1) break; while(n%i == 0){ res[i]++; n /= i; } } if(n != 1) res[n]++; return res; } int main(){ int p, q; cin >> p >> q; int x, y; q /= ext_gcd(p,q,x,y); auto pr = pf(q); int ans = 1; for(auto pa : pr) ans *= pa.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": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <cmath> using namespace std; long gcd(long a, long b){ if(b == 0) return a; return gcd(b, a%b); } int main(){ long p, q; cin >> p >> q; long tmp = gcd(q, p); p /= tmp; q /= tmp; long ans = 1; long root = sqrt(q) + 1; vector<bool> hurui(root, true); for(int i=2; i<=root; i++){ if(hurui[i] == true){ if(i <= root){ for(int j=2*i; j<=root; j+=i){ hurui[j] = false; } } if(q%i == 0){ ans *= i; while(q%i == 0) q /= i; if(q == 1) break; } } } 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": [] }
CORRECT
cpp
#include <stdio.h> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> typedef long long int ll; #define BIG_NUM 2000000000 using namespace std; int main(){ int p,q,pre_limit,limit; scanf("%d %d",&p,&q); pre_limit = sqrt(q); for(int i = 2; i <= pre_limit; i++){ while(p%i == 0 && q %i == 0){ p /= i; q /= i; } } if(q % p == 0)q /= p; limit = sqrt(q); int ans = 1; for(int i = 2; i <= limit; i++){ if(q%i == 0){ ans *= i; while(q % i == 0)q /= i; } } ans *= q; printf("%d\n",ans); 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": [] }
CORRECT
cpp
#include<iostream> using namespace std; unsigned gcd(unsigned a, unsigned b) { if(a < b) return gcd(b, a); unsigned r; while ((r=a%b)) { a = b; b = r; } return b; } int main(){ long long p,q,t=1,gc; cin >> p >> q; gc = gcd(p,q); p /= gc; q /= gc; for(int i=2;i*i<=q;i++){ if(q%i==0){ t*=i; while(q%i==0) q/=i; } } t*=q; cout << t << 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": [] }
CORRECT
cpp
#include<iostream> 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++) { while(b%(i*i)<1)b/=i; } 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": [] }
CORRECT
cpp
#include <iostream> #include <vector> #define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++) using namespace std; typedef long long ll; int P, Q; bool p[1000000]; vector<int> v; int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a % b); } bool prime(int n) { REP(i, 0, v.size()) if(n % v[i] == 0) return false; return true; } ll solve() { ll ans = 1; REP(i, 0, v.size()) if(Q % v[i] == 0) { ans *= v[i]; while(Q % v[i] == 0) Q /= v[i]; } if(prime(Q)) ans *= Q; return ans; } int main(void) { REP(i, 0, 1000000) p[i] = true; p[0] = p[1] = false; REP(i, 0, 1000000) if(p[i]) for(int j = i * 2; j < 1000000; j += i) p[j] = false; REP(i, 0, 1000000) if(p[i]) v.push_back(i); cin >> P >> Q; Q = Q / gcd(P, Q); cout << solve() << 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": [] }
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 solve(int n) { int res = 1; for (int i = 2; i * i <= n; i++) { if (n % i) continue; res *= i; while (n % i == 0) n /= i; } if (n != 1) res *= n; return res; } int main(void) { int p, q; cin >> p >> q; cout << solve(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": [] }
CORRECT
cpp
#include <iostream> #include <algorithm> //#include <numeric> using namespace std; #define FOR(i,a,b) for (size_t i = a; i < b; i++) #define REP(i,b) FOR(i,0,b) #define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--) #define RREP(i,a) RFOR(i,a,0) #define INF 1e7 long gcd(long a, long b) { long r; do { r = b % a; //printf("%ld = %ld * ? + %ld\n", b, a, r); b = a; a = r; } while(r); return b; } long search_root(long a) { int ans = 1, tmp = a; for (int i = 2; i * i <= tmp; i++) { //cout<<i<<tmp<<endl; if (tmp % i == 0) { ans *= i; while (tmp % i == 0) tmp /= i; } } return ans * tmp; } int main() { long p, q; cin>>p>>q; cout<<search_root(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": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define ll long long #define var auto using namespace std; ll gcd(ll a, ll b){ while(true){ if (a == 0) return b; b %= a; if (b == 0) return a; a %= b; } } int main(){ ll p, q; cin >> p >> q; var g = gcd(p, q); p /= g; q /= g; ll res = 1; for (ll i = 2; i * i <= q; i++){ if (q % i != 0) continue; res *= i; while (q % i == 0){ q /= i; } } res *= q; 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; int gcd(int x, int y) { if (x<=y) return gcd(y, x); if (x%y == 0) return y; else return gcd(y, x%y); } int main() { int p, q; cin >> p >> q; int r = q/gcd(p, q); int s = r; int res = 1; for (int i = 2; i*i <= r; ++i) { if (s%i == 0) { res *= i; while (s%i == 0) s /= i; } } res *= s; cout << res << 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": [] }
CORRECT
cpp
#include <cstdio> #include <utility> int gcd(int m, int n) { while (n) std::swap(m %= n, n); return m; } int main() { int p, q; scanf("%d %d", &p, &q); int m = q / gcd(p, q); int res = 1; for (int i = 2; i*i <= m; ++i) { if (m % i == 0) { res *= i; do { m /= i; } while (m % i == 0); } } if (m > 1) res *= m; printf("%d\n", res); }
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": [] }
CORRECT
cpp
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> using namespace std; typedef long long ll; const ll MOD = 1000000007; const ll INF = (ll)1000000007 * 1000000007; const double EPS = 1e-9; typedef pair<int, int> P; typedef unsigned int ui; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) int gcd(int a, int b) { if (b == 0)return a; return gcd(b, a%b); } int main() { int isp[100000] = {}; vector<int> v; Rep(i, 2, 100000) { if (!isp[i]) { v.push_back(i); for(int j=2*i;j<100000;j+=i){ isp[j] = 1; } } } int p, q; cin >> p >> q; int d = gcd(q,p); q /= d; int out = 1; int now = 0; while (q > 1) { if (q%v[now] == 0) { out*=v[now]; while (q%v[now] == 0)q /= v[now]; } else if (v[now] > (int)sqrt(q + 0.5)) { out *= q; q = 1; } else now++; } if (out == 1)out = 2; cout << out << 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": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; ll power(ll e, ll x) { if (x == 0) return 1; if (x % 2 == 0) return power(e * e, x / 2); return e * power(e, x - 1); } int main() { ll a, b; cin >> a >> b; a %= b; map<ll, int> amp, bmp; for (ll i = 2; i * i <= a; i++) { if (a % i == 0) { amp[i]++; a /= i; i--; } } for (ll i = 2; i * i <= b; i++) { if (b % i == 0) { bmp[i]++; b /= i; i--; } } if (a > 1) amp[a]++; if (b > 1) bmp[b]++; ll ans = 1; for (auto &v : bmp) { if (v.second - amp[v.first] >= 1) ans *= v.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": [] }
CORRECT
cpp
#include<iostream> #include<map> #include<algorithm> #include <iomanip> #include <cmath> #include <sstream> #include <unordered_map> #include <unordered_set> #include <deque> #include <vector> #include <bitset> #include <queue> #include <set> #include <stack> #include <string> #include <cstring> #include <cstdio> #include <list> constexpr int INF = 1050000000; constexpr int MOD = 1000000007; constexpr long long LONGINF = 1005000000000000000; using namespace std; using ll = long long; /* UnionFind class UnionFind { private: std::vector<int> parent; std::vector<int> height; std::vector<int> m_size; public: UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) { for (int i = 0; i < size_; ++i) parent[i] = i; } void init(int size_) { parent.resize(size_); height.resize(size_, 0); m_size.resize(size_, 1); for (int i = 0; i < size_; ++i) parent[i] = i; } int find(int x) { if (parent[x] == x) return x; return parent[x] = find(parent[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; int t = size(x) + size(y); m_size[x] = m_size[y] = t; if (height[x] < height[y]) parent[x] = y; else parent[y] = x; if (height[x] == height[y]) ++height[x]; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { if (parent[x] == x) return m_size[x]; return size(parent[x] = find(parent[x])); } }; */ int GCD(int a, int b) { while (b) { int tmp = a % b; a = b; b = tmp; } return a; } int s(int a) { int n = a; map<int, int> mp; for (int i = 2; i*i <= a; i++) { while (n%i == 0) { n /= i; mp[i]; } } mp[n]; int check = 1; for (auto x : mp) { check *= x.first; } return check; } int main() { int p, q; cin >> p >> q; if (p == 0 && q == 0) { return 0; } int G = GCD(p, q); p /= G; q /= G; cout << s(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": [] }
CORRECT
cpp
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> VI; typedef vector<VI> VVI; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const int INF = numeric_limits<int>::max() / 2; const int NEG_INF = numeric_limits<int>::min() / 2; const int MOD = 1e9 + 7; //a,b???GCD ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } //?´???°?????? vector<ll> divisor(ll n){ vector<ll> res; //res.push_back(1);res.push_back(n); ll tmp=n; for(int i=2;i*i<=n;i++){ if(tmp%i!=0)continue; res.push_back(i); while(tmp%i==0){ tmp/=i; } } if(tmp!=n) res.push_back(tmp); sort(res.begin(),res.end()); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll p,q;cin>>p>>q; ll g=gcd(p,q); p/=g;q/=g; vector<ll> res=divisor(q); if(res.size()==0) cout<<q<<endl; else{ ll ret=1; for(int i=0;i<(int)res.size();i++) ret*=res[i]; cout<<ret<<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 lcm(long int a, long int b) { if (a < b) { swap(a, b); } if (!b) { return a; } return lcm(b, a % b); } int main() { long int i, p, q, lc, cl; double lm, buf, df, m; cin >> p >> q; lc = lcm(p, q); p /= lc; q /= lc; lm = log(q) / log(2); cl = (int)lm + 1; for (i = 1; i <= cl; i++) { buf = pow(q, (double)1 / i); df = (int)buf + 1 - buf; if (df == 1 || df < 0.0001) { m = buf; } } cout << (long int)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() { long x, y; cin >> x >> y; long z = y; if (x < y) swap(x, y); int sum = 0; do { x = x % y; swap(x, y); sum++; } while (y != 0); cout << z / 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
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 buf_u = q,buf_d = p,buf = 0; while(buf_u%buf_d!=0) { buf = buf_d; buf_d = buf_u%buf_d; buf_u = buf; } buf = q/buf_d; buf_u = buf; for(int i = 2; i < Math.sqrt(buf)+1;i++) { while(buf%i==0) { buf /= i; } if(buf == 1) { buf_u = i; break; } buf = buf_u; } System.out.println(buf_u); } }
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 MOD = 1000000007; const long long INF = (long long)1000000007 * 1000000007; const double EPS = 1e-9; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int isp[100000] = {}; vector<int> v; for (int i = 2; i < 100000; i++) { if (!isp[i]) { v.push_back(i); for (int j = 2 * i; j < 100000; j += i) { isp[j] = 1; } } } int p, q; cin >> p >> q; int d = gcd(q, p); q /= d; int out = 1; int now = 0; while (q > 1) { if (q % v[now] == 0) { out *= v[now]; while (q % v[now] == 0) q /= v[now]; } else if (v[now] > (int)sqrt(q + 0.5)) { out *= q; q = 1; } else now++; } if (out == 1) out = 2; cout << out << 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 a, b; cin >> a >> b; int c = gcd(a, b); cout << b / c << 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.ArrayList; import java.util.Scanner; public class Main{ public static void main(String args[]) { ArrayList<Long> yaku = new ArrayList<Long>(); Scanner scn = new Scanner(System.in); long p = scn.nextLong(), q = scn.nextLong(); scn.close(); long qs; long ans = q; long bp = p,bq = q,buf = p; long r; while(bq % bp != 0) { buf = bq % bp; bq = bp; bp = buf; } for(long i = 1;i <= Math.sqrt(buf);i++) { if(buf%i==0) { yaku.add(i); yaku.add(buf/i); } } ans = q/buf; for(int i = 0;i < yaku.size();i++) { qs = q/yaku.get(i); for(int j = 30;j > 1;j--) { r = Math.round(Math.pow(qs,1/(double)(j))); if(Math.pow(r,j)==qs)ans = Math.min(ans, r); } } System.out.println(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 namespace std; bool prim[10000000]; int main(){ int p,q; cin>>p>>q; int a=__gcd(p,q); p/=a,q/=a; for(int i=2;i<=q;i++){ if(q%i==0&&(q/i)%i==0)q/=i,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
python3
prime = [2] def check(x): for i in prime: if x % i ==0: return False elif x < i * i: break return True def set(): for i in range(3,10**5,2): if check(i): prime.append(i) set() #print(prime) p,q = [int(i) for i in input().split(' ')] for i in prime: while True: if p % i ==0 and q % i == 0: p = p//i q = q//i else: break ans = 1 for i in prime: if q % i == 0: # print(q,i) q = q // i ans *= i while q % i ==0: q = q // i ans *= q print(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 namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); long long p, q; cin >> p >> q; q = q / __gcd(p, q); int ans = 1; vector<int> primeNumbers; vector<int> flag(q + 1, true); for (int i = 2; i <= sqrt(q); i++) { if (flag[i]) { primeNumbers.push_back(i); for (int j = i + i; j <= q; j += i) { flag[j] = false; } } } for (int i = sqrt(q); i <= q; i++) { if (flag[i]) { primeNumbers.push_back(i); } } for (auto i : primeNumbers) { if (q % i == 0) { q /= i; ans *= 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; 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(10e16); 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; }