Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++) v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
while (a % b != 0) {
a %= b;
swap(a, b);
}
return b;
}
int main() {
map<int, int> mpii;
for (int i = (int)(1); i < (int)(40000); ++i) mpii[i * i] = i;
int p, q;
cin >> p >> q;
long long g = gcd(p, q);
p /= g;
q /= g;
while (mpii.find(p) != mpii.end() && mpii.find(q) != mpii.end()) {
p = mpii[p];
q = mpii[q];
}
cout << q << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp |
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
int i,j;
int p,q;
cin>>p>>q;
int g=__gcd(p,q);
q=q/g;
vector<bool> prime(1005,true);
loop(i,2,1005)
if(prime[i])
for(j=2;i*j<=1000;j++)
prime[i*j]=false;
prime[0]=prime[1]=false;
ll ans=1;
loop(i,1,q+1){
if(prime[i]&&q%i==0)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;
bool prim[20000000];
int main(){
int p,q;
cin>>p>>q;
int a=__gcd(p,q);
p/=a,q/=a;
int ans=1;
for(int i=2;i*i<=q;i++)
if(prim[i]==0&&q%i==0){
for(int j=2;j<20000000/i;j++) prim[i*j]=1;
}
for(int i=2;i<20000000;i++) if(prim[i]==0&&q%i==0)ans*=i;
if(ans==1)ans=q;
cout <<ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int pow_search(int number) {
int last = sqrt(number);
for (int i = 2; i <= last; i++) {
int temp = number;
while (1) {
if (temp == 1) {
return i;
}
if (temp % i == 0) {
temp /= i;
} else {
break;
}
}
}
return number;
}
int gcd(int p, int q) {
int p_temp;
while (1) {
if (q == 0) {
break;
}
p_temp = p;
p = q;
q = p_temp % q;
}
return p;
}
int main(void) {
int p;
int q;
cin >> p >> q;
int result = q / gcd(p, q);
result = pow_search(result);
cout << result << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp |
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
int i,j;
int p,q;
cin>>p>>q;
int g=__gcd(p,q);
q=q/g;
vector<bool> prime(1000005,true);
loop(i,2,100000)
if(prime[i])
for(j=2;i*j<=1000000;j++)
prime[i*j]=false;
prime[0]=prime[1]=false;
ll ans=1;
loop(i,1,sqrt(q+1)){
if(prime[i]&&q%i==0)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;
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
int a, b;
cin >> a >> b;
cout << b / gcd(a, b) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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 = 50;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;
int main(){
int p,q;
cin>>p>>q;
int a=__gcd(p,q);
p/=a,q/=a;
cout <<q<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int lsgcd(int a, int b) {
if (b == 0) return a;
return lsgcd(b, a - (a / b * b));
}
int main() {
int p, q;
cin >> p >> q;
int ans = q / lsgcd(q, p);
while (sqrt(ans) * sqrt(ans) == ans) ans = sqrt(ans);
cout << (ans) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
int i,j;
int p,q;
cin>>p>>q;
q=q/__gcd(p,q);
ll ans=1;
for(i=2;i*i<=q;i++)if(q%i==0){
ans*=i;
while(q%i==0)q/=i;
}
cout<<ans<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> primes;
const int MA = 30000000;
bool t[MA * 2];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= MA; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= MA; j += i) t[j] = 1;
}
}
}
int main() {
eratosu();
cin >> p >> q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (now > p || now > q) break;
while (p % now == 0 && q % now == 0) p /= now, q /= now;
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
int p,q,t,ans;
cin>>p>>q;
ans=t=q/__gcd(p,q);
for(int i=2;i*i<=t;i++)
if(!(t%i))ans=i;
cout<<ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second
#define INF 2147483600
#define long long long
int main(){
int p,q;
cin>>p>>q;
int g = __gcd(p,q);
q /= g;
cout << max(q,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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++) v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
while (a % b != 0) {
a %= b;
swap(a, b);
}
return b;
}
int main() {
map<int, int> mpii;
for (int i = (int)(1); i < (int)(40000); ++i) mpii[i * i] = i;
int p, q;
cin >> p >> q;
q /= gcd(p, q);
set<int> soinsu;
for (int i = (int)(2); i < (int)(sqrt(q) + 1); ++i) {
while (q % i == 0) {
q /= i;
soinsu.insert(i);
}
}
long long ans = 1;
for (int a : soinsu) ans *= a;
cout << ans << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
}
System.out.println(q/buf_d);
}
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(){
int p,q;
cin>>p>>q;
int a=__gcd(p,q);
p/=a,q/=a;
int ans=1;
for(int i=2;i<=q;i++){
if(q%i==0){
ans*=i;
while(q%i==0)q/=i;
}
}
cout << ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const int INF = 100000000;
using namespace std;
int gcd(int x, int y) {
int r;
if (x < y) swap(x, y);
while (y > 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
int main() {
int p, q;
cin >> p >> q;
q /= gcd(p, q);
int ans = -1;
for (int i = 2; i * i <= 1000000000; i++) {
int temp = q;
while (temp % i == 0) {
if (temp == i) ans = i;
temp /= i;
}
if (ans != -1) break;
}
if (ans == -1)
cout << q << endl;
else
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>
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;
long long max(long long a, int b) { return max(a, long long(b)); }
long long max(int a, long long b) { return max(long long(a), b); }
long long min(long long a, int b) { return min(a, long long(b)); }
long long min(int a, long long b) { return min(long long(a), b); }
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
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;
int res = 1;
;
while (q > 1) {
if (q % i == 0) {
res *= i;
while (q % i == 0) q /= i;
}
++i;
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int p, q;
cin >> p >> q;
for (long long int i = 2; i * i <= q; i++) {
if (p % i == 0 && q % i == 0) {
p /= 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": []
} | IN-CORRECT | java | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
public class Main {
static PrintWriter out;
static InputReader ir;
static void solve() {
int p = ir.nextInt();
if(p==0){
out.println(2);
System.exit(0);
}
int q = ir.nextInt();
int a = q / gcd(p, q);
boolean[] prime=sieveOfEratosthenes(a);
int ret=1;
for(int i=0;i<=Math.sqrt(a);i++){
if(!(a%i==0))
continue;
if(prime[i])
ret*=i;
if(prime[a/i])
ret*=a/i;
}
out.println(ret);
}
public static boolean[] sieveOfEratosthenes(int n) {
boolean[] res = new boolean[n + 1];
Arrays.fill(res, true);
res[0] = res[1] = false;
for (int i = 2; i <= Math.sqrt(n); i++) {
if (res[i]) {
for (int j = i + i; j <= n; j += i) {
res[j] = false;
}
}
}
return res;
}
public static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main(String[] args) throws Exception {
ir = new InputReader(System.in);
out = new PrintWriter(System.out);
solve();
out.flush();
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
return a = max(a, b);
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &i : v) is >> i;
return is;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
const string delimiter = "\n";
for (int i = (int)(0); i < (int)(v.size()); i++) {
os << v[i];
if (i != v.size() - 1) os << delimiter;
}
return os;
}
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
return (a % b ? gcd(a % b, b) : b);
}
int main() {
cin.sync_with_stdio(false);
cout << fixed << setprecision(10);
long long a, b;
cin >> a >> b;
long long g = b / gcd(a, b);
long long ans = g;
for (int i = (int)(1); i < (int)(1e9); i++) {
long double tmp = pow(g, 1.0 / i);
if (tmp < 2) break;
if (tmp == long long(tmp)) chmin(ans, long long(tmp));
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.lang.Integer.parseInt;
/**
* Let's Solve Geometric Problems
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
String[] words;
line = br.readLine();
long p, q;
p = parseInt(line.substring(0, line.indexOf(' ')));
q = parseInt(line.substring(line.indexOf(' ') + 1));
//reduce
q /= gcd(p, q);
//factorize
List<Long> f = factors(q);
if (f.size() != 1) {
Map<Long, Integer> map = new HashMap<>();
for (long l : f) {
map.putIfAbsent(l, 0);
map.put(l, map.get(l) + 1);
}
if (map.size() != 1) {
boolean multi = true;
int _c = -1;
for (int c : map.values()) {
if (_c == -1) {
_c = c;
continue;
} else {
if (c != _c) {
multi = false;
break;
}
}
}
q = 1;
for (long l : map.keySet()) {
q *= l;
}
} else {
q = f.get(0);
}
}
System.out.println(q);
}//end main
static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static List<Long> factors(long n) {
if (n == 0) return new ArrayList<Long>() {
{
add(1L);
}
};
List<Long> fs = new ArrayList<>();
long p = 2;
for (long i = p; i <= n; i++) {
while (n % i == 0) {
fs.add(i);
n /= i;
}
}
return fs;
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
for (auto&& x : vec) is >> x;
return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
for (long long i = (0), __last_i = (vec.size()); i < __last_i; i++) {
if (i) os << " ";
os << vec[i];
}
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T> >& vec) {
for (long long i = (0), __last_i = (vec.size()); i < __last_i; i++) {
if (i) os << endl;
os << vec[i];
}
return os;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long p, q;
cin >> p >> q;
cout << q / gcd(p, q) << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
long long mod = (long long)1e09 + 7;
int in(void) {
int i;
scanf("%d", &i);
return i;
}
long long llin(void) {
long long i;
scanf("%lld", &i);
return i;
}
double din(void) {
double i;
scanf("%lf", &i);
return i;
}
void chin(char s[]) { scanf("%s", s); }
void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
int cmp(const void *a, const void *b) {
return *(long long *)a - *(long long *)b;
}
int cmp_r(const void *a, const void *b) {
return *(long long *)b - *(long long *)a;
}
int char_cmp(const void *a, const void *b) {
return strcmp((char *)a, (char *)b);
}
int char_cmp_r(const void *a, const void *b) {
return strcmp((char *)b, (char *)a);
}
void swap(int *a, int *b) {
int t = *a;
*a = *b;
*b = t;
}
long long gcd(long long x, long long y) { return x % y ? gcd(y, x % y) : y; }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int p[100000 + 1];
void eratosthenes(void) {
int i, j;
for (i = 2; i < 100000; i++) p[i] = 1;
for (i = 2; i * i < 100000; i++) {
if (p[i]) {
for (j = 2 * i; j <= 100000; j = j + i) {
p[j] = 0;
}
}
}
}
int main(void) {
int a = in(), q = in(), i, ans = 1;
eratosthenes();
for (i = 0; i < 100000 + 1; i++) {
if (p[i]) {
while (a % i == 0 && q % i == 0) a /= i, q /= i;
if (q % i == 0) ans *= i;
}
}
print(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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set;
using std::setprecision;
using std::stack;
using std::string;
using std::vector;
int gcd(int p, int q) {
int temp;
if (q == 0) {
return p;
} else {
temp = p % q;
p = q;
q = temp;
return gcd(p, q);
}
return 0;
}
bool prime_check(int number) {
if (number == 2) {
return true;
} else if (number % 2 == 0) {
return false;
}
for (int i = 3; i * i <= number; i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
int main(void) {
int p;
int q;
int ans = 1;
cin >> p >> q;
q /= gcd(p, q);
for (int i = 2; i * i <= q; i++) {
if (prime_check(i) == true && q % i == 0) {
ans *= i;
}
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> primes;
const int MA = 10000000;
bool t[MA * 2];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= MA; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= MA; j += i) t[j] = 1;
}
}
}
bool check(int x) {
int a = x;
int aa = x;
while (aa <= q) {
if (aa == q) return 1;
aa = aa * a;
}
return 0;
}
int main() {
eratosu();
cin >> p >> q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (sqrt(now) > p || sqrt(now) > q) break;
while (p % now == 0 && q % now == 0) p /= now, q /= now;
}
for (int i = 2; i <= 10000; i++) {
if (check(i)) {
cout << i << endl;
break;
}
}
cout << "WA";
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
queue<long long int> q;
vector<bool> prime(1000000000 + 1, true);
void make(long long int M) {
prime[0] = prime[1] = false;
long long int i;
for (i = 2; i * i <= M + 1; i++) {
if (prime[i]) {
long long int j = 2;
q.push(i);
while (i * j < M + 1) {
prime[i * j] = false;
j++;
}
}
}
return;
}
int main() {
long long int a, b;
cin >> a >> b;
make(max(a, b));
long long int c = b / gcd(a, b);
long long int ans = 1;
long long int ma = c;
while (!q.empty()) {
long long int d = q.front();
if (c % d == 0) {
while (c % d == 0) c /= d;
ans *= d;
}
q.pop();
}
ans *= c;
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
int main() {
long long A, B, v = 1;
cin >> A >> B;
B /= gcd(A, B);
for (int i = 2; i * i < B; i++) {
if (B % i == 0) {
v *= i;
while (B % i == 0) B /= i;
}
}
cout << B * v << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
p,q = LI()
g = fractions.gcd(p,q)
rr.append(q//g)
break
return '\n'.join(map(str, rr))
print(main())
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> primes;
const int MA = 30000000;
bool t[MA * 2];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= MA; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= MA; j += i) t[j] = 1;
}
}
}
bool check(int x) {
int a = x;
int aa = x;
while (aa <= q) {
if (aa == q) return 1;
aa = aa * a;
}
return 0;
}
int main() {
eratosu();
cin >> p >> q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (now > p || now > q) break;
while (p % now == 0 && q % now == 0) p /= now, q /= now;
}
for (int i = 2; i <= 10000; i++) {
if (check(i)) {
cout << i << endl;
break;
}
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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 = q;
for (int i = 2; i * i <= q; i++) {
temp = q;
while (temp % i == 0) {
temp /= i;
}
if (temp == 1) {
ans = min(ans, i);
break;
}
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long p, q;
cin >> p >> q;
cout << q / gcd(p, q) << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int p, q;
cin >> p >> q;
int m = 1;
for (int i = 1; i <= p; i++) {
if (p % i == 0 && q % i == 0) {
m = i;
}
}
cout << q / m << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java |
import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
long p = scn.nextLong(), q = scn.nextLong();
scn.close();
long qs;
long ans;
long bp = p,bq = q,buf = p;
while(bq % bp != 0) {
buf = bq % bp;
bq = bp;
bp = buf;
}
ans = q/buf;
for(int i = 2;i <= Math.sqrt(q/buf);i++) {
for(int j = 1;j <= buf;j++) {
if(p%j == 0 && q %j == 0) {
qs = q/j;
while(qs % i == 0) {
qs /= i;
}
if(qs == 1) {
ans = i;
break;
}
}
}
}
System.out.println(ans);
}
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int gcd(int 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);
}
if ((int)sqrt(n) == sqrt(n)) {
cout << sqrt(n) << endl;
} else {
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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;
long long max(long long a, int b) { return max(a, long long(b)); }
long long max(int a, long long b) { return max(long long(a), b); }
long long min(long long a, int b) { return min(a, long long(b)); }
long long min(int a, long long b) { return min(long long(a), b); }
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
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;
int res = 1;
int s = q;
while (s > 1) {
if (s % i == 0) {
res *= i;
while (s % i == 0) s /= i;
}
if (i * i > q) break;
++i;
}
if (res == 1)
cout << q << endl;
else
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long solve(long long a, long long b) {
long long x = max(a, b), y = min(a, b);
if (x % y == 0)
return y;
else
return solve(x % y, y);
}
int main() {
long long p, q, r, ans;
vector<long long> prime(100000);
cin >> p >> q;
r = solve(p, q);
p /= r;
q /= r;
long long i = 2, j = 0, temp = q;
while (temp != 1) {
if (temp % i == 0) {
temp /= i;
prime[j]++;
} else {
if (i == 2)
i = 3;
else {
double ii;
ii = static_cast<double>(i);
if (ii > pow(temp, 0.5)) {
j++;
prime[j]++;
} else
i += 2;
}
if (prime[j] > 0) j++;
}
}
sort(prime.begin(), prime.begin() + j);
if (prime[0] == 1)
;
else {
long long k = 2;
while (prime[0] != 1 && prime[0] >= k) {
if (prime[0] % k == 0) {
int all = 1;
for (int l = 0; l < j; l++) {
if (prime[l] % k != 0) {
if (k == 2)
k = 3;
else
k += 2;
all = 0;
break;
}
}
if (all = 1) {
long long qq;
double kk;
kk = static_cast<double>(k);
qq = pow(q, 1 / kk);
if (q % qq > 0)
q = qq + 1;
else
q = qq;
for (int l = 0; l <= j; l++) prime[l] /= k;
}
} else {
if (k == 2)
k = 3;
else
k += 2;
}
}
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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(10e9) + 1;
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 = i; i * j < M; j++) {
isPrime[i * j] = false;
}
}
long long ans = 1;
for (long long i = 2; i < M; i++) {
if (q % i == 0 && isPrime[i] == true) {
ans *= i;
}
}
if (q > 1 && ans == 1) {
ans = q;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <iostream>
using namespace std;
int p,q,count,ans,k;
int prime[100000];
char a[1000005];
int gcd(int b,int a){
int c=1;
while(1){
c=a%b;
a=b;
b=c;
if(c==0)break;
}
return a;
}
void check(){
count=0;
for(int i=2;i<1000005;i++){
if(a[i]=='1')continue;
prime[count]=i;
count++;
for(int j=i;j<1000005;j+=i){
a[j]='1';
}
}
}
int main(){
for(int i=2;i<1000005;i++){
a[i]='0';
}
check();
cin>> p>>q;
q=q/gcd(p,q);
ans=1;
k=0;
while(q>1){
if(q%prime[k]==0)ans*=prime[k];
while(q%prime[k]==0)q/=prime[k];
k++;
}
cout<< ans<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int 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;
}
}
cout << q << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int P, Q;
bool p[100000000];
vector<int> v;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long solve() {
long long ans = 1;
for (int i = ((int)0); i < ((int)v.size()); i++)
if (Q % v[i] == 0) ans *= v[i];
if (ans == 1) ans *= Q;
return ans;
}
int main(void) {
for (int i = ((int)0); i < ((int)100000000); i++) p[i] = true;
p[0] = p[1] = false;
for (int i = ((int)0); i < ((int)100000000); i++)
if (p[i])
for (int j = i * 2; j < 100000000; j += i) p[j] = false;
for (int i = ((int)0); i < ((int)100000000); i++)
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(){
int p, q;
cin >> p >> q;
cout << q / __gcd(p, q) << endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long p, q;
cin >> p >> q;
int va = q;
for (long long i = 2; i * i <= va; i++) {
if (p == 1) break;
while (p % i == 0 && q % i == 0) {
p /= i;
q /= i;
}
}
for (long long i = 2; i * i <= va; i++) {
while (q % i == 0 && p < q / 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": []
} | IN-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;
}
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int p, q;
cin >> p >> q;
int g = __gcd(p, q);
int b = q / g;
int ans = 1;
rep(i, 100005) if (i > 1) {
if (b % i == 0) {
ans *= i;
while (b % i == 0) b /= i;
}
}
cout << ans << endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int const MOD = 1e9 + 7;
int GCD(int x, int y) {
if (y == 0) return x;
return GCD(y, x % y);
}
int main(void) {
ll p, q;
cin >> p >> q;
int d = GCD(p, q);
p /= d;
q /= d;
int ans = 1;
for (int i = 2; i <= sqrt(q); ++i) {
if (q % i == 0) {
ans *= i;
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
vector<bool> primes;
void make_primes(int n) {
primes.resize(n + 1, true);
primes[0] = primes[1] = false;
for (int i = 2; i < sqrt(n); i++) {
if (primes[i]) {
for (int j = 0; i * (j + 2) < n; j++) primes[i * (j + 2)] = false;
}
}
}
int main() {
int p, q;
cin >> p >> q;
q = q / gcd(p, q);
vector<int> sie;
make_primes(q);
for (int i = 0; i < primes.size(); i++) {
if (primes[i]) sie.push_back(i);
}
set<int> s;
int t = 0;
while (1) {
if (q % sie[t] == 0) {
s.insert(sie[t]);
q /= sie[t];
} else {
t++;
}
if (q == 1) {
break;
}
}
long long ans = 1;
set<int>::iterator it = s.begin();
while (it != s.end()) {
ans *= (*it);
it++;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q;
cin >> p >> q;
for (int i = 2;; i++) {
if (q % i == 0) {
cout << max(i, q / i) << endl;
break;
}
}
}
|
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 | from fractions import gcd
from math import sqrt
if __name__ == "__main__":
p, q = map(int, input().split())
ans = q / gcd(p, q)
while True:
if sqrt(ans).is_integer():
ans = int(sqrt(ans))
else:
print(int(ans))
break
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math
p = int(input())
q = int(input())
print(int(q/math.gcd(p,q)))
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b);
signed main() {
long long p;
scanf("%lld", &p);
;
long long q;
scanf("%lld", &q);
;
while (p && q) {
long long base = gcd(p, q);
q /= base;
long long ans = 1;
for (long long i = 2; i <= q; i++) {
if (!(q % i)) {
ans *= i;
while (!(q % i)) {
q /= i;
}
}
}
cout << ans << endl;
cin >> p >> q;
}
return 0;
}
long long gcd(long long a, long long b) {
if (!b) {
return a;
} else {
gcd(b, a % b);
}
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return gcd(b, a % b);
}
signed main() {
long long p, q;
cin >> p >> q;
cout << q / gcd(p, q) << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> primes;
const int MA = 10000000;
bool t[MA * 2];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= MA; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= MA; j += i) t[j] = 1;
}
}
}
bool check(int x) {
int a = x;
int aa = x;
while (aa <= q) {
if (aa == q) return 1;
aa = aa * a;
}
return 0;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
eratosu();
cin >> p >> q;
int gc = gcd(p, q);
int np = p, nq = q;
p = np / gc;
q = nq / gc;
int ans = 1, qq = q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (q % now == 0) ans *= now;
while (q % now == 0) q /= now;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
int P, Q;
int main() {
cin >> P >> Q;
cout << max(2, Q / gcd(P, Q)) << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
int i,j;
int p,q;
cin>>p>>q;
int g=__gcd(p,q);
q=q/g;
while(1){
int a=sqrt(q);
if(a*a==q)q=sqrt(q);
else break;
}
cout<<q<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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;
long long max(long long a, int b) { return max(a, long long(b)); }
long long max(int a, long long b) { return max(long long(a), b); }
long long min(long long a, int b) { return min(a, long long(b)); }
long long min(int a, long long b) { return min(long long(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;
res *= fact(n / i);
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q;
cin >> p >> q;
for (int i = 2; i * i <= q; i++) {
if (p % i == 0 && q % i == 0) {
p /= 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int main() {
int p, q, m, oriq;
scanf("%d %d", &p, &q);
oriq = q;
m = p % q;
while (m) {
p = q;
q = m;
m = p % q;
}
printf("%d\n", oriq / q);
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
int t = 1;
map<int, int> m;
for (; t * t <= b; t++) m[t * t] = t;
a /= gcd(a, b), b /= gcd(a, b);
while (m[a] && m[b]) a = m[a], b = m[b];
cout << b << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long p, q;
scanf("%lld %lld", &p, &q);
long long m = 1;
for (int i = 1; i <= p; i++) {
if (p % i == 0 && q % i == 0) {
m = i;
}
}
printf("%lld\n", q / m);
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int calc(int n) {
int i;
for (i = 2; i * i < n; i++) {
if (n % i == 0) {
int temp = n / i;
while (temp % i == 0) {
n /= i;
temp /= i;
}
}
}
return n;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main(void) {
int p, q;
scanf("%d %d", &p, &q);
q /= gcd(p, q);
int ans = calc(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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd ( ll a, ll b ){
ll c;
while ( a != 0 ) {
c = a; a = b%a; b = c;
}
return b;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll p,q;
cin >>p>>q;
ll g=gcd(p,q);
ll res=q/g;
// if(res==1) res=10;
cout << max(res,2) <<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 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 (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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int m, int n) {
while (n > 0) {
int r = m % n;
m = n;
n = r;
}
return m;
}
int main() {
int p, q;
scanf("%d%d", &p, &q);
int r = gcd(q, p);
printf("%d\n", q / r);
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.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();
int q = ir.nextInt();
int a = q / gcd(p, q);
boolean[] prime=sieveOfEratosthenes(a);
int ret=1;
for(int i=0;i<a;i++){
if(!prime[i])
continue;
if(a%i==0)
ret*=i;
}
out.println(ret);
}
public static boolean[] sieveOfEratosthenes(int n) {
boolean[] res = new boolean[n + 1];
Arrays.fill(res, true);
res[0] = res[1] = false;
for (int i = 2; i <= Math.sqrt(n); i++) {
if (res[i]) {
for (int j = i + i; j <= n; j += i) {
res[j] = false;
}
}
}
return res;
}
public static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main(String[] args) throws Exception {
ir = new InputReader(System.in);
out = new PrintWriter(System.out);
solve();
out.flush();
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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;
long long max(long long a, int b) { return max(a, long long(b)); }
long long max(int a, long long b) { return max(long long(a), b); }
long long min(long long a, int b) { return min(a, long long(b)); }
long long min(int a, long long b) { return min(long long(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;
if (n != i * i) res *= fact(n / i);
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long p, q;
cin >> p >> q;
long long va = q;
long long ans = 0;
for (long long i = 2; i * i <= va; i++) {
if (ans != 0) break;
if (q % i == 0) {
ans = -1;
while (q % i == 0) {
q /= i;
}
if (q == 1) ans = i;
}
}
if (ans != 0 && ans != -1) {
cout << ans << endl;
} else {
q = va;
for (long long i = 2; i <= va; i++) {
if (p == 1) break;
while (p % i == 0 && q % i == 0) {
p /= 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": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
int p,q,a,ans=1;
set<int> s;
cin>>p>>q;
q/=__gcd(p,q);
for(int i=2;i<=q;i++){
if(!(q%i))s.insert(i),q/=i;
if(q==1)break;
}
set<int>::iterator ite;
for(ite=s.begin();ite!=s.end();ite++)
ans*=(*ite);
cout<<ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
bool isPrime[100000];
int main() {
int p, q;
cin >> p >> q;
int d = gcd(p, q);
q /= d;
fill(isPrime, isPrime + 100000, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i < 100000; i++) {
if (!isPrime[i]) continue;
for (int k = 2; i * k < 100000; k++) isPrime[k * i] = false;
}
int r = -1;
vector<pair<int, int> > V;
for (int i = 2; i < q && i < 100000; i++) {
if (!isPrime[i]) continue;
if (q % i == 0) {
int cnt = 0;
while (q % i == 0) {
cnt++;
q /= i;
}
if (r == -1) {
r = cnt;
} else {
r = gcd(r, cnt);
}
V.emplace_back(i, cnt);
}
}
int ans = 1;
for (auto v : V) {
int k = v.first;
for (int i = 0; i < v.second / r; i++) ans *= k;
}
cout << ans << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int 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;
cout << q << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second
#define INF 2147483600
#define long long long
int main(){
int p,q;
cin>>p>>q;
int g = __gcd(p,q);
q /= g;
cout << q << endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> primes;
const int MA = 10000000;
bool t[MA * 2];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= MA; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= MA; j += i) t[j] = 1;
}
}
}
bool check(int x) {
int a = x;
int aa = x;
while (aa <= q) {
if (aa == q) return 1;
aa = aa * a;
}
return 0;
}
int main() {
eratosu();
cin >> p >> q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (now > p || now > q) break;
while (p % now == 0 && q % now == 0) p /= now, q /= now;
}
for (int i = 2; i <= 10000; i++) {
if (check(i)) {
cout << i << endl;
break;
}
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main(void) {
int p, q;
scanf("%d %d", &p, &q);
printf("%d\n", q / gcd(p, q));
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long p, q;
cin >> p >> q;
long long va = q;
long long ans = 0;
for (long long i = 2; i * i <= va; i++) {
if (ans != 0) break;
if (q % i == 0) {
ans = -1;
while (q % i == 0) {
q /= i;
}
if (q == 1) ans = i;
}
}
if (ans != 0 && ans != -1) {
cout << ans << endl;
} else {
q = va;
for (long long i = 2; i <= va; i++) {
if (p == 1) break;
while (p % i == 0 && q % i == 0) {
p /= i;
q /= i;
}
}
for (long long i = 2; i <= va; i++) {
if (p == 1) break;
while (q % i == 0 && p > q / 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> primes;
bool t[10000000];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= 10000000; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= 10000000; j += i) t[j] = 1;
}
}
}
int main() {
eratosu();
cin >> p >> q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
while (p % now == 0 && q % now == 0) p /= now, q /= now;
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
int q,p,t,ans=1,i,j,c;
cin>>q>>p;t=p;
p/=__gcd(q,p);
if(p%3==0)ans*=3;
if(p%2==0)ans*=2;
for(i=5;i*i<=t;i++)
if(p%i==0)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 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);
}
if ((int)sqrt(n) == sqrt(n)) {
n = sqrt(n);
}
if ((int)sqrt(n) == sqrt(n)) {
if (q % 2 == 0) {
while (n % 2 != 1) {
n = n / 2;
}
cout << 2 * n << endl;
}
} else {
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long solve(long long a, long long b) {
long long x = max(a, b), y = min(a, b);
if (x % y == 0)
return y;
else
return solve(x % y, y);
}
int main() {
long long p, q, r, ans;
vector<long long> prime(100000);
cin >> p >> q;
r = solve(p, q);
p /= r;
q /= r;
long long i = 2, j = 0, temp = q;
while (temp != 1) {
if (temp % i == 0) {
temp /= i;
prime[j]++;
} else {
if (i == 2)
i = 3;
else {
double ii;
ii = static_cast<double>(i);
if (ii > pow(temp, 0.5)) {
j++;
prime[j]++;
break;
} else
i += 2;
}
if (prime[j] > 0) j++;
}
}
sort(prime.begin(), prime.begin() + j);
if (prime[0] == 1)
;
else {
long long k = 2;
while (prime[0] != 1 && prime[0] >= k) {
if (prime[0] % k == 0) {
int all = 1;
for (int l = 0; l < j; l++) {
if (prime[l] % k != 0) {
if (k == 2)
k = 3;
else
k += 2;
all = 0;
break;
}
}
if (all = 1) {
long long qq;
double kk;
kk = static_cast<double>(k);
qq = pow(q, 1 / kk);
if (q % qq > 0) {
q = qq + 1;
} else
q = qq;
for (int l = 0; l <= j; l++) prime[l] /= k;
}
} else {
if (k == 2)
k = 3;
else
k += 2;
}
}
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int lsgcd(int a, int b) {
if (b == 0) return a;
return lsgcd(b, a - (a / b * b));
}
int main() {
int p, q;
cin >> p >> q;
int ans = q / lsgcd(q, p);
cout << (ans) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int 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; }
signed main() {
int p, q;
cin >> p >> q;
int g = gcd(p, q);
cout << q / g << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
int main() {
long long A, B;
cin >> A >> B;
cout << B / gcd(A, B) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-7;
const int inf = 1e9;
const long long INF = 2e18;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
long long a, b;
cin >> a >> b;
long long t = b / gcd(a, b);
for (long long i = 2; i * i <= t; i++) {
long long q = t;
while (q % i == 0) q /= i;
if (q == 1) {
cout << i << endl;
return 0;
}
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int gcd(int a, int b) {
if (a < b) {
int c = a;
a = b;
b = c;
}
if (a % b == 0) return b;
return gcd(b, a % b);
}
bool judgeprime(int n) {
if (n == 1) return false;
int i, j;
j = (int)sqrt(n);
for (i = 2; i < j; i++)
if (n % i == 0) break;
return i == j;
}
int nextprime(int prime) {
prime++;
while (judgeprime(prime++) == false)
;
return prime;
}
int main(void) {
int p, q;
scanf("%d%d", &p, &q);
q /= gcd(p, q);
int prime = 2, ans = 1;
while (q > 1) {
if (q % prime == 0) {
ans *= prime;
while (q % prime == 0) q /= prime;
}
prime = nextprime(prime);
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
int t = 1;
map<int, int> m;
for (; t * t <= b; t++) m[t * t] = t;
int c = gcd(a, b);
a /= c, b /= c;
while (m[a] && m[b]) a = m[a], b = m[b];
cout << b << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
int p, q;
cin >> p >> q;
int d = gcd(p, q);
q /= d;
for (long long i = 2; i * i <= q; i++) {
long long x = i * i;
while (x < q) x *= i;
if (x == q) {
q = i;
break;
}
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
#define ZERO(a) memset(a,0,sizeof(a))
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
#define exists find_if
#define forall all_of
using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double; using vld = vector<ld>;
using vi = vector<int>; using vvi = vector<vi>; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using Pos = complex<double>;
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) { o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; }
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U> ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U, typename V> ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; }
vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; }
template <typename T> istream& operator>>(istream& i, vector<T>& o) { rep(j, o.size()) i >> o[j]; return i;}
string bits_to_string(ll input, ll n=64) { string s; rep(i, n) s += '0' + !!(input & (1ll << i)); reverse(all(s)); return s; }
template <typename T> unordered_map<T, ll> counter(vector<T> vec){unordered_map<T, ll> ret; for (auto&& x : vec) ret[x]++; return ret;};
string substr(string s, P x) {return s.substr(x.fi, x.se - x.fi); }
struct ci : public iterator<forward_iterator_tag, ll> { ll n; ci(const ll n) : n(n) { } bool operator==(const ci& x) { return n == x.n; } bool operator!=(const ci& x) { return !(*this == x); } ci &operator++() { n++; return *this; } ll operator*() const { return n; } };
size_t random_seed; namespace std { using argument_type = P; template<> struct hash<argument_type> { size_t operator()(argument_type const& x) const { size_t seed = random_seed; seed ^= hash<ll>{}(x.fi); seed ^= (hash<ll>{}(x.se) << 1); return seed; } }; }; // hash for various class
namespace myhash{ const int Bsizes[]={3,9,13,17,21,25,29,33,37,41,45,49,53,57,61,65,69,73,77,81}; const int xor_nums[]={0x100007d1,0x5ff049c9,0x14560859,0x07087fef,0x3e277d49,0x4dba1f17,0x709c5988,0x05904258,0x1aa71872,0x238819b3,0x7b002bb7,0x1cf91302,0x0012290a,0x1083576b,0x76473e49,0x3d86295b,0x20536814,0x08634f4d,0x115405e8,0x0e6359f2}; const int hash_key=xor_nums[rand()%20]; const int mod_key=xor_nums[rand()%20]; template <typename T> struct myhash{ std::size_t operator()(const T& val) const { return (hash<T>{}(val)%mod_key)^hash_key; } }; };
template <typename T> class uset:public std::unordered_set<T,myhash::myhash<T>> { using SET=std::unordered_set<T,myhash::myhash<T>>; public: uset():SET(){SET::rehash(myhash::Bsizes[rand()%20]);} };
template <typename T,typename U> class umap:public std::unordered_map<T,U,myhash::myhash<T>> { public: using MAP=std::unordered_map<T,U,myhash::myhash<T>>; umap():MAP(){MAP::rehash(myhash::Bsizes[rand()%20]);} };
struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; }
struct init_{init_(){ gettimeofday(&start, NULL); ios::sync_with_stdio(false); cin.tie(0); srand((unsigned int)time(NULL)); random_seed = RAND_MAX / 2 + rand() / 2; }} init__;
static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;
#define ldout fixed << setprecision(40)
int main(void) {
ll p, q; cin >> p >> q;
ll g = __gcd(p, q); p /= g, q /= g;
ll ret = 1;
set<ll> primes;
repi(i, 2, 40000) {
for (auto p : primes)
if (i % p == 0)
goto SKIP;
if (q % i == 0) ret *= i;
primes.insert(i);
while (!(q % i))
q /= i;
SKIP:;
}
if (q > 1)
ret *= q;
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
vector<bool> primes;
void make_primes(int n) {
primes.resize(n + 1, true);
primes[0] = primes[1] = false;
for (int i = 2; i < sqrt(n); i++) {
if (primes[i]) {
for (int j = 0; i * (j + 2) < n; j++) primes[i * (j + 2)] = false;
}
}
}
int main() {
int p, q;
cin >> p >> q;
q = q / gcd(p, q);
vector<int> sie;
make_primes(q);
for (int i = 0; i < primes.size(); i++) {
if (primes[i]) sie.push_back(i);
}
set<int> s;
int t = 0;
while (1) {
if (q % sie[t] == 0) {
s.insert(sie[t]);
q /= sie[t];
} else {
t++;
}
if (q == 1) {
break;
}
}
int ans = 1;
set<int>::iterator it = s.begin();
while (it != s.end()) {
ans *= (*it);
it++;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int p, q;
cin >> p >> q;
for (long long int i = 2; i * i <= q; i++) {
do {
if (p % i == 0 && q % i == 0) {
p /= i;
q /= i;
}
} while (p % i == 0 && q % i == 0);
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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
print(q)
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 50;
int solve();
long long gcd(long long p, long long q) {
if (q == 0) {
return p;
}
return gcd(q, p % q);
}
int main(void) {
while (solve()) {
}
return 0;
}
int solve() {
long long p, q, g;
cin >> p >> q;
g = gcd(max(p, q), min(p, q));
p = p / g;
q = q / g;
const long long M = sqrt(10e15);
std::vector<bool> isPrime(M, true);
isPrime[1] = false;
for (long long i = 2; i < sqrt(M) + 10; i++) {
if (isPrime[i] == false) {
continue;
}
for (long long j = i; i * j < M; j++) {
isPrime[i * j] = false;
}
}
long long ans = 1;
for (long long i = 2; i < M; i++) {
if (isPrime[i] == true && q % i == 0) {
ans *= i;
}
}
if (ans == 1 && q > 1) {
ans = q;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math
f=lambda n:min(int(i) for i in (round(n**(1/i),10) for i in range(1,int(math.log(n,2))+2)) if int(i)==i)
p,q=map(int,input().split())
if f(q)==q:
e=math.gcd(p,q)
q/=e
e=f(q)
if f(q)!=q:
q/=e
print(int(q))
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
int P,Q;
public int gcd(int x,int y){
return y == 0 ? x : gcd(y,x%y);
}
public void solve() {
P = nextInt();
Q = nextInt();
int g = gcd(P,Q);
P /= g;
Q /= g;
for(int i = 2;;i++){
for(long j = i;j <= 1e9;j*=i){
if(Q == j){
out.println(i);
return;
}
}
}
}
public static void main(String[] args) {
out.flush();
new Main().solve();
out.close();
}
/* Input */
private static final InputStream in = System.in;
private static final PrintWriter out = new PrintWriter(System.out);
private final byte[] buffer = new byte[2048];
private int p = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (p < buflen)
return true;
p = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0)
return false;
return true;
}
public boolean hasNext() {
while (hasNextByte() && !isPrint(buffer[p])) {
p++;
}
return hasNextByte();
}
private boolean isPrint(int ch) {
if (ch >= '!' && ch <= '~')
return true;
return false;
}
private int nextByte() {
if (!hasNextByte())
return -1;
return buffer[p++];
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = -1;
while (isPrint((b = nextByte()))) {
sb.appendCodePoint(b);
}
return sb.toString();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int p, q;
cin >> p >> q;
int r = gcd(q, p);
p /= r;
q /= r;
int ans = 1;
for (int i = 2; i <= q; i++) {
if (q % i != 0) continue;
ans *= i;
while (q % i == 0) q /= i;
}
cout << ans << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
solve();
}
public static void solve(){
Scanner sc = new Scanner(System.in);
int p = sc.nextInt();
int q = sc.nextInt();
if(q%p==0){
q /= p;
p = 1;
}
boolean[] judge = new boolean[(int)Math.sqrt(1000000000)+5];
Arrays.fill(judge,true);
judge[0] = false;
judge[1] = false;
for(int i=2;i<judge.length;i++){
if(judge[i]){
if(p%i==0 && q%i==0){
p /= i;
q /= i;
}
for(int j=i*2;j<judge.length;j+=i){
judge[j] = false;
}
}
}
for(int i=2;i<judge.length;i++){
if(judge[i] && q%(i*i)==0){
q /= i;
i--;
}
}
System.out.println(q);
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.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 <= qs;i++) {
if(qs % i ==0) {
while(qs % i == 0) {
qs /=i;
}
ans *= i;
}
}
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;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
vector<long long> res;
long long tmp = n;
for (int i = 2; i <= tmp; i++) {
if (tmp % i != 0) continue;
if (i == n) break;
res.push_back(i);
while (tmp % i == 0) {
tmp /= i;
}
}
sort(res.begin(), res.end());
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long p, q;
cin >> p >> q;
long long g = gcd(p, q);
p /= g;
q /= g;
vector<long long> res = divisor(q);
if (res.size() == 0)
cout << q << endl;
else {
long long 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;
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;
}
}
}
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": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
long p = scn.nextLong(), q = scn.nextLong();
scn.close();
long qs;
long ans = q;
for(int i = 2;i <= q;i++) {
for(int j = 1;j <= p;j++) {
if(p%j == 0 && q %j == 0) {
qs = q/j;
while(qs % i == 0) {
qs /= i;
}
if(qs == 1)ans = Math.min(i,ans);
}
}
}
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;
int p, q;
vector<int> yakusuu;
int main() {
cin >> p >> q;
for (int i = 1; i <= p / 2; i++) {
if (p % i == 0) {
yakusuu.push_back(i);
}
}
for (int j = 0; j < yakusuu.size(); j++) {
if (q % yakusuu[j] == 0) q = q / yakusuu[j];
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | /* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */
int main(){
ll p, q;
cin >> p >> q;
ll g = __gcd(p, q);
p /= g, q /= g;
vector<pair<ll, ll>> v;
rep(i, 2, inf){
ll x = i * i;
if (x > 1000000000) break;
while (x <= 1000000000){
v.emplace_back(x, i);
x *= i;
}
}
ll res = q;
each(x, v) if (x.first % q == 0) chmin(res, x.second);
cout << res << endl;
} |
Subsets and Splits