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 double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1 << 30;
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
int a, b;
cin >> a >> b;
b /= gcd(a, b);
bool h = false;
for (int t = 2; t * t <= b; t++) {
int r = b;
while (r % t == 0) r /= t;
if (r == 1) {
cout << t << endl;
h = true;
break;
}
}
if (!h) 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 a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int p, q;
cin >> p >> q;
q /= gcd(p, q);
for (int i = 2; i < 10000; i++) {
double x = log(q) / log(i);
if (ceil(x) == floor(x)) {
cout << i << endl;
return 0;
}
}
cout << q << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int p, int q) { return p % q == 0 ? q : gcd(q, p % q); }
int main() {
int p, q;
cin >> p >> q;
int d = gcd(p, q);
int ans = q / d;
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
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();
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;
}
}
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 | cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
int p,q,t,ans=1,num;
set<int> s;
cin>>p>>q;
num=t=q/__gcd(p,q);
for(int i=2;i*i<=num;i++){
if(!(num%i)){
s.insert(i);
while(!(num%i))num/=i;
}
}
set<int>::iterator ite=s.begin();
while(ite!=s.end())ans*=*ite,ite++;
if(ans==1)ans=t;
cout<<ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toStr(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
const int MOD = 1000000007;
int gcd(int x, int y) {
if (x < y) {
swap(x, y);
}
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
int main() {
int p, q;
cin >> p >> q;
int m = sqrt(q);
vector<int> prime(m + 1, 1);
prime[0] = prime[1] = 0;
for (int i = (2); i <= (m); ++i) {
if (prime[i]) {
for (int j = i * i; j <= m; j += i) {
prime[j] = 0;
}
}
}
int ans = 1;
q /= gcd(p, q);
for (int i = (2); i <= (m); ++i) {
if ((prime[i] == 1) && (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>
#define N 1000005
using namespace std;
int p,q,t,ans,prime[N];
set<int> s;
int main(){
for(int i=0;i<N;i++)prime[i]=1;
prime[0]=prime[1]=0;
for(int i=0;i*i<N;i++){
if(!prime[i])continue;
for(int j=i*2;j<N;j+=i)
prime[j]=0;
}
cin>>p>>q;
t=q/__gcd(p,q);
for(int i=0;i*i<=t;i++)
if(prime[i]&&!(t%i)){
s.insert(i);
if(prime[t/i])s.insert(t/i);
}
ans=1;
set<int>::iterator ite=s.begin();
while(ite!=s.end()){
ans*=(*ite);
ite++;
}
if(ans==1)ans=t;
cout<<ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int p, q;
cin >> p >> q;
p = gcd(p, q);
q /= p;
set<int> s;
for (int i = 2; i <= q;) {
if (q % i == 0) {
q /= i;
s.insert(i);
} else {
i++;
}
}
int r = 1;
for (auto it = begin(s); it != end(s); it++) {
r *= *it;
}
cout << r << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int main() {
int p, q;
int i, n;
int ans = 1;
scanf("%d%d", &p, &q);
if (p < q)
n = p;
else
n = q;
for (i = 2; i < n; i++) {
while (1) {
if ((p % i == 0) && (q % i == 0)) {
p /= i;
q /= i;
} else
break;
}
}
for (i = 2; i <= q; i++) {
if (q % i == 0) {
ans *= i;
while (q % i == 0) q /= i;
}
}
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;
b /= gcd(a, b);
while (m[b]) 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<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(100000,true);
loop(i,2,100000)
if(prime[i])
for(j=2;i*j<=100000;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;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
signed main() {
std::ios::sync_with_stdio(false);
std::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 | cpp | #include<bits/stdc++.h>
#define N 100005
using namespace std;
int p,q,t,ans,prime[N];
set<int> s;
int main(){
for(int i=0;i<N;i++)prime[i]=1;
prime[0]=prime[1]=0;
for(int i=0;i*i<N;i++){
if(!prime[i])continue;
for(int j=i*2;j<N;j+=i)
prime[j]=0;
}
cin>>p>>q;
t=q/__gcd(p,q);
for(int i=0;i<=t;i++)
if(prime[i]&&!(t%i))s.insert(i);
ans=1;
set<int>::iterator ite=s.begin();
while(ite!=s.end()){
ans*=(*ite);
ite++;
}
cout<<ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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();
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;
}
}
}
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 | cpp | #include <bits/stdc++.h>
using namespace std;
using lli = long long int;
lli gcd(lli x, lli y) { return (y == 0 ? x : gcd(y, x % y)); }
lli solve(lli p, lli q) {
const lli NMAX = 100008;
vector<lli> factor(NMAX, 0);
for (lli n = 2; n < NMAX; ++n) {
if (factor[n]) {
continue;
}
for (lli k = 2; k * n < NMAX; ++k) {
factor[k * n] = n;
}
}
lli ans = 1;
for (lli n = 2; q > 1; ++n) {
if (factor[n] || (q % n != 0)) {
continue;
}
while (q % n == 0) {
q /= n;
}
ans *= n;
}
return max<lli>(2, ans);
}
int main() {
lli P, Q;
cin >> P >> Q;
const lli G = gcd(P, Q);
P /= G, Q /= G;
cout << solve(P, Q) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | 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 <= (long long)sqrt(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 <bits/stdc++.h>
using namespace std;
int main() {
long long p, q;
cin >> p >> q;
long long P = p, Q = q;
while (p % q != 0) {
p = p % q;
swap(p, q);
}
long long va = Q;
P /= q;
Q /= q;
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 | UNKNOWN | #include <bits/stdc++.h>
int main(void) {
int b, p, q, r;
scanf("%d %d", &p, &q);
b = q;
r = q % p;
while (r != 0) {
q = p;
p = r;
r = q % p;
}
printf("%d\n", b / p);
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int p, q;
cin >> p >> q;
int g = __gcd(p, q);
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;
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=4;i<=p;i++){
for(j=2,c=0;j*j<=i;j++)if(i%j==0)c++;
if(!c&&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 namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)
const int inf = 1 << 25;
const ll INF = 1LL << 55;
int main()
{
ll p, q;
cin >> p >> q;
vector<int> factor;
q = q / __gcd(p, q);
for(int x = 2; q != 1; x++) {
if(q % x == 0) {
factor.push_back(x);
while(q % x == 0) q /= x;
}
}
ll ans = 1;
rep(i, factor.size()) ans *= factor[i];
cout << ans << endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long p, q;
long long int gcd(long long int x, long long int y) {
if (x % y == 0) return y;
return gcd(y, x % y);
}
void factor(long long n, vector<pair<long long, long long> > &v) {
vector<long long> p;
for (int i = 2; i <= n; ++i) {
bool f = true;
for (int j = 0; j < p.size(); ++j)
if (i % p[j] == 0) {
f = false;
break;
}
if (f) p.push_back(i);
}
for (int i = 0; i < p.size(); ++i) {
int t = 0;
while (n % p[i] == 0) {
n /= p[i];
++t;
}
v.push_back(pair<long long, long long>(p[i], t));
if (n == 1) break;
}
}
int main() {
cin >> p >> q;
long long g = gcd(p, q);
p /= g;
q /= g;
vector<pair<long long, long long> > v;
factor(q, v);
long long mi = q;
long long ma = 1;
for (int i = 0; i < v.size(); ++i) {
mi = min(mi, v[i].second);
ma = max(ma, v[i].second);
}
if (mi == ma) {
long long t = 1;
for (int i = 0; i < v.size(); ++i) t *= v[i].first;
q = t;
}
cout << q << "\n";
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
bool prime[10000000];
int main(){
for(int i=2;i*i<10000000;i++)
for(int j=2;j<10000000/i&&!prime[i];j++) prime[i*j]=1;
vector <int> n;
for(int i=2;i<10000000;i++)if(!prime[i])n.push_back(i);
int p,q;
cin>>p>>q;
int a=__gcd(p,q);
p/=a,q/=a;
int ans=1;
for(int i=0;i<n.size();i++)if(q%n[i]==0)ans*=n[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 namespace std;
long long Gcd(long long a, long long b) {
long long gcd;
long long c = max(a, b);
long long d = min(a, b);
while (true) {
if (c % d == 0) {
gcd = d;
goto C;
} else {
c -= d;
if (c <= d) swap(c, d);
}
}
C:
return gcd;
}
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;
const long long int MOD = 1000000007;
long long int N, M, K, H, W, L, R;
int gcd(int a, int b) {
if (a < b) swap(a, b);
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
M /= gcd(N, M);
for (int i = 2; i * i <= M; i++) {
long long int box = i;
while (box < M) {
box *= i;
}
if (box == M) {
cout << i << endl;
return 0;
}
}
cout << M << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | 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));
}
}
int main() {
int p, q;
cin >> p >> q;
q = q / gcd(p, q);
int qq = q / gcd(p, q);
long long ans = 1;
for (int j = 2; j * j <= qq; j++) {
if (qq % j == 0) {
ans *= j;
while (qq % j == 0) {
qq /= j;
}
}
}
if (qq != 1) ans *= qq;
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 p, q;
cin >> p >> q;
long long P = p, Q = q;
while (p % q != 0) {
p = p % q;
swap(p, q);
}
long long va = q;
P /= q;
Q /= q;
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 | cpp | #include <bits/stdc++.h>
using namespace std;
vector<long long> prime;
long long gcd(long long a, long long b) {
if (b <= 1) {
return b;
} else {
return gcd(b, a % b);
}
}
void pri() {
vector<bool> state(5001, false);
for (long long i = 2; i < 5000; i++) {
if (!state[i]) {
prime.push_back(i);
for (long long j = 2; i * j < 5000; j++) {
state[i * j] = true;
}
}
}
}
signed main() {
pri();
long long p;
scanf("%lld", &p);
long long q;
scanf("%lld", &q);
while (p && q) {
if (p >= q) {
cout << 2 << endl;
} else {
long long ret = gcd(p, q);
long long ans = 1;
while (ret != 1) {
for (long long i = 0; i < prime.size(); i++) {
if (!(ret % prime[i])) {
ans *= prime[i];
ret /= prime[i];
}
}
}
cout << ans << endl;
}
cin >> p >> q;
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
uint32_t gcd(uint32_t p, uint32_t q) {
if (q > p) return gcd(q, p);
if (q == 0)
return p;
else
return gcd(q, p % q);
}
int32_t main() {
uint32_t p, q;
cin >> p >> q;
uint32_t g = gcd(p, q);
uint32_t qq = q / g;
for (uint32_t i = 2; i < q / g; i++) {
if (qq % i == 0) {
cout << i << endl;
break;
}
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll p, q;
while (cin >> p >> q) {
ll ans = 1;
for (int i = 2; i <= 1e5; ++i) {
int c = 0;
while (p % i == 0) p /= i, ++c;
while (q % i == 0) q /= i, --c;
while (c < 0) ans *= i, ++c;
}
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;
bool p[1000000];
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];
return ans;
}
int main(void) {
for (int i = ((int)0); i < ((int)1000000); i++) p[i] = true;
p[0] = p[1] = false;
for (int i = ((int)0); i < ((int)1000000); i++)
if (p[i])
for (int j = i * 2; j < 1000000; j += i) p[j] = false;
for (int i = ((int)0); i < ((int)1000000); 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;
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<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
ll p,q;
int main(){
cin>>p>>q;
for(ll i=2;i<=1000;i++){
if(p*i%q==0){
cout<<i<<endl;
break;
}
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.Integer.parseInt;
/**
* Let's Solve Geometric Problems
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
String[] words;
line = br.readLine();
int p, q;
p = parseInt(line.substring(0, line.indexOf(' ')));
q = parseInt(line.substring(line.indexOf(' ') + 1));
System.out.println(q / gcd(p, q));
}//end main
static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b > a) {
long long t = b;
b = a;
a = t;
}
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long root(long long n) {
int c;
while ((1ll << c) < n) c++;
for (int i = c; i >= 2; i--) {
long long t = 1;
while (pow(t, i) <= n) {
if (pow(t, i) == n) {
return t;
}
t++;
}
}
return n;
}
int main(int argc, char const *argv[]) {
long long a, b;
cin >> a >> b;
cout << root(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;
int main() {
long long p, q;
cin >> p >> q;
for (long long i = 2; i * i <= q; i++) {
if (p == 1) break;
while (p % i == 0 && q % i == 0) {
p /= i;
q /= i;
}
}
for (long long i = 2; i * i <= q; i++) {
if ((double)pow(q, (float)1 / i) - (long long int)pow(q, (float)1 / i) ==
0) {
q /= (long long int)pow(q, (float)1 / 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;
const int MAX_N = 100005;
int prime[MAX_N];
bool is_prime[MAX_N];
int sieve(int n) {
int p = 0;
for (int i = 0; i <= n; i++) {
is_prime[i] = true;
}
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = i;
for (int j = 2 * i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
return p;
}
int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int main() {
int p, q;
cin >> p >> q;
q /= gcd(p, q);
int mx = (int)(sqrt(q));
sieve(mx);
int ans = 1;
for (int i = 0; i < (int)mx; ++i) {
if (is_prime[i] && q % i == 0) {
ans *= i;
while (q % i == 0) {
q /= i;
}
}
}
cout << ans * ((q == 1) ? 1 : q) << "\n";
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
int gcd(int p, int q) {
if (q > p) std::swap(p, q);
while (p % q != 0) {
int r = p % q;
p = q;
q = r;
}
return q;
}
int main(void) {
cout << std::fixed << std::setprecision(10);
cin.tie(0);
std::ios::sync_with_stdio(false);
int p, q;
cin >> p >> q;
int div = gcd(p, q);
p /= div;
q /= div;
for (int i = 2; i < 31614; i++) {
int tgt = q;
while (tgt % q == 0) {
tgt /= q;
}
if (tgt == 1) {
cout << q << endl;
return 0;
}
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <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);
}
while ((int)sqrt(n) == sqrt(n)) {
n = sqrt(n);
}
for (int i = 2; i * i < n; i++) {
if (n % (i * i) == 0) {
n = n / i;
i--;
}
}
cout << n << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
int p, q;
scanf("%d%d", &p, &q);
printf("%d\n", q / gcd(q, p));
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
#define rep(i,j) for (int (i)=0;(i)<(int)(j);++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
int p, q;
cin >> p >> q;
int k = __gcd(p, q);
p /= k;
q /= k;
int q_ = q;
vector<pair<int, int>> ans;
for (int i=2; i<=sqrt(q); ++i) {
if (q_%i == 0) {
pair<int, int> p = make_pair(i, 1);
q_ /= i;
while (q_%i == 0) {
p.second++;
q_ /= i;
}
ans.push_back(p);
}
}
if (q_ > 1) ans.push_back(make_pair(q_, 1));
int a = 1;
for (int i = 0; i < ans.size(); ++i) {
a *= ans[i].first;
}
cout << a << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int 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<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
int pow(int x, int n){
if(n == 0)return 1;
int res = pow(x, n/2);
if(n%2 == 1) return x*res*res;
return res*res;
}
vector<int> Prime(int p){
vector<bool> is_prime(p + 10, true);
vector<int> prime;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= p; i++) {
if(is_prime[i])prime.push_back(i);
for (int j = 2*i; j <= p; j+=i) {
is_prime[j] = false;
}
}
return prime;
}
map<int, int> fact(int n){
map<int, int> res;
for (int i = 1; i*i <= n; i++) {
if(n%i == 0){
if(n/i == i)res[i]++;
else res[i]++, res[n/i]++;
}
}
return res;
}
int main(){
int p, q;
std::cin >> p >> q;
int gcd = __gcd(p, q), ans;
p /= gcd;
q /= gcd;
for (int i = 2; i*i <= q; i++) {
int tmp = i;
for (int j = 2; tmp <= q; j++) {
tmp *= i;
if(tmp == q){
std::cout << i << std::endl;
return 0;
}
}
}
std::cout << q << std::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;
if(ans==1&&q!=t)ans=t;
cout<<ans<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 50;
int solve();
long long gcd(long long p, long long q) {
if (q == 0) {
return p;
}
return gcd(q, p % q);
}
int main(void) {
while (solve()) {
}
return 0;
}
int solve() {
long long p, q, g;
cin >> p >> q;
g = gcd(max(p, q), min(p, q));
p = p / g;
q = q / g;
const long long M = sqrt(10e9) + 10;
std::vector<bool> isPrime(M, true);
isPrime[1] = false;
for (long long i = 2; i < M; i++) {
if (isPrime[i] == false) {
continue;
}
for (long long j = 2; i * j < M; j++) {
isPrime[i * j] = false;
}
}
long long ans = 1;
for (long long i = 2; i < (long long)sqrt(M); i++) {
if (q % i == 0 && isPrime[i] == true) {
ans *= i;
}
}
if (ans == 1 && q > 1) {
ans = q;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(){
int p,q;
cin>>p>>q;
int a=__gcd(p,q);
p/=a,q/=a;
int ans=q;
if(q%p==0) {
ans=2;
while(q%ans)ans++;
}
cout <<ans<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | 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(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 | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAX_P = 32000;
bool primes[MAX_P + 1];
int gen_primes(int maxp, vector<int> &pnums) {
memset(primes, true, sizeof(primes));
primes[0] = primes[1] = false;
int p;
for (p = 2; p * p <= maxp; p++)
if (primes[p]) {
pnums.push_back(p);
for (int q = p * p; q <= maxp; q += p) primes[q] = false;
}
for (; p <= maxp; p++)
if (primes[p]) pnums.push_back(p);
return (int)pnums.size();
}
bool prime_decomp(int n, vector<int> &pnums, vector<pair<int, int> > &pds) {
pds.clear();
int pn = pnums.size();
for (int i = 0; i < pn; i++) {
int pi = pnums[i];
if (pi * pi > n) {
if (n > 1) pds.push_back(pair<int, int>(n, 1));
return true;
}
if (n % pi == 0) {
int fi = 0;
while (n % pi == 0) n /= pi, fi++;
pds.push_back(pair<int, int>(pi, fi));
}
}
return false;
}
int gcd(int m, int n) {
while (n > 0) {
int r = m % n;
m = n;
n = r;
}
return m;
}
int powi(int a, int b) {
int p = 1;
while (b) {
if (b & 1) p *= a;
a *= a;
b >>= 1;
}
return p;
}
int main() {
vector<int> pnums;
int pn = gen_primes(MAX_P, pnums);
int p, q;
scanf("%d%d", &p, &q);
int n = q / gcd(q, p);
vector<pair<int, int> > pds;
prime_decomp(n, pnums, pds);
int r = pds[0].second;
for (int i = 1; r > 1 && i < pds.size(); i++) r = gcd(r, pds[i].second);
int m = 1;
for (int i = 0; i < pds.size(); i++)
m *= pow(pds[i].first, pds[i].second / r);
printf("%d\n", m);
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q;
vector<int> primes;
const int MA = 30000000;
bool t[MA * 2];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= MA; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= MA; j += i) t[j] = 1;
}
}
}
bool check(int x) {
int a = x;
int aa = x;
while (aa <= q) {
if (aa == q) return 1;
aa = aa * a;
}
return 0;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
eratosu();
cin >> p >> q;
int gc = gcd(p, q);
int np = p, nq = q;
p = np / gc;
q = nq / gc;
long long ans = 1, qq = q;
int cnt = 0;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (q % now == 0) ans *= now, cnt++;
while (q % now == 0) q /= now;
}
if (cnt == 0) ans *= q;
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long p, q;
cin >> p >> q;
for (long long i = 2; i * i <= q; i++) {
if (p % i == 0 && q % i == 0) {
do {
p /= i;
q /= i;
} while (p % i == 0 && q % i == 0);
}
}
for (long long i = 2; i * i <= q; i++) {
if ((double)pow(p, (float)1 / i) - (long long int)pow(p, (float)1 / i) ==
0 &&
(double)pow(q, (float)1 / i) - (long long int)pow(q, (float)1 / i) ==
0) {
p /= (long long int)pow(p, (float)1 / i);
q /= (long long int)pow(q, (float)1 / 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 | UNKNOWN | #include <bits/stdc++.h>
int in(void) {
int i;
scanf("%d", &i);
return i;
}
long long llin(void) {
long long i;
scanf("%lld", &i);
return i;
}
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; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int is_prime(int n) {
int i;
for (i = 2; i * i <= n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main(void) {
int p = in(), q = in(), i, t;
q /= gcd(p, q);
for (i = 2; i < q; i++) {
if (is_prime(i)) {
t = q;
while (t && !(t % i)) {
t /= i;
if (t == 1) {
goto END;
}
}
}
}
END:
print(t == 1 ? i : 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 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;
}
int main(void) {
int p;
int q;
cin >> p >> q;
q /= gcd(p, q);
for (int i = 2; i * i <= q; i++) {
while (q % i == 0) {
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;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
cin.sync_with_stdio(false);
long long p, q;
cin >> p >> q;
long long np, nq;
np = p / gcd(p, q);
nq = q / gcd(p, q);
for (long long i = (long long)(2); i < (long long)(100001); i++) {
for (long long j = i; j < 1000000000; j *= i) {
if (j == nq) {
cout << i << endl;
return 0;
}
}
}
cout << max(2LL, nq) << 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;
}
}
cout << endl;
}
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;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | // ?????¬???????????¬??????
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;
signed main() {
int p, q; cin >> p >> q;
int g = __gcd(p, q);
p /= g, q /= g;
for(int i=2; i*i<=q; i++) {
int x = q;
while(x % i == 0) x /= i;
if(x == 1) {
cout << i << endl;
return 0;
}
}
cout << q << endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long p, q;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
cin >> p >> q;
long long r = gcd(p, q);
p /= r;
q /= r;
for (int i = 2; i * i <= q; i++) {
long long D = 1;
if (q == i) continue;
while (true) {
D *= i;
if (D > q) break;
if (D == q) {
cout << i << endl;
goto E;
}
}
}
cout << q << endl;
E:;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
int main()
{
int p,q;
cin >>p >>q;
cout << q/__gcd(p,q) << endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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 || n % 2 == 0) return false;
int i, j;
j = (int)sqrt(n);
bool k = true;
for (i = 3; i < j; i += 2)
if (n % i == 0) {
k = false;
break;
}
return k;
}
int nextprime(int prime) {
prime++;
while (judgeprime(prime++) == false)
;
return prime - 1;
}
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;
}
if (judgeprime(q)) {
ans *= q;
break;
}
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 | python3 | from fractions import gcd
if __name__ == "__main__":
p, q = map(int, input().split())
print(q//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;
int main() {
long long p, q;
cin >> p >> q;
for (long long i = 2; i * i <= q; i++) {
if (p % i == 0 && q % i == 0) {
do {
p /= i;
q /= i;
} while (p % i == 0 && q % i == 0);
}
}
for (int i = 2; i * i <= q; i++) {
if ((int)pow(p, 0.5) == (double)pow(p, 0.5) &&
(int)pow(q, 0.5) == (double)pow(q, 0.5)) {
p /= pow(p, 0.5);
q /= pow(q, 0.5);
}
}
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;
cin>>p>>q;
cout<<q/__gcd(p,q)<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main{
public static void main(String args[]){
try(Scanner sc = new Scanner(System.in)){
long p = sc.nextLong(), q = sc.nextLong();
long memo = q/gcd(p,q);
long ans = -1;
long i = 1;
while(ans!=memo){
ans = memo;
while(i*i < memo){
i++;
}
if(i*i==memo){
memo = i;
}
}
System.out.println(ans);
}
}
private static long gcd(long p, long q){
if(p < q) {
return gcd(q, p);
}
if(q==0){
return p;
}
return gcd(q, p%q);
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int p, q;
cin >> p >> q;
q /= gcd(p, q);
for (int i = 2;; i++) {
double x = log(q) / log(i);
if (ceil(x) == floor(x)) {
cout << 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 | cpp | #include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 31) - 1;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long p, q;
int main() {
cin >> p >> q;
cout << q / gcd(p, q) << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
int pow(int x, int n){
if(n == 0)return 1;
int res = pow(x, n/2);
if(n%2 == 1) return x*res*res;
return res*res;
}
vector<int> Prime(int p){
vector<bool> is_prime(p + 10, true);
vector<int> prime;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= p; i++) {
if(is_prime[i])prime.push_back(i);
for (int j = 2*i; j <= p; j+=i) {
is_prime[j] = false;
}
}
return prime;
}
map<int, int> fact(int n){
map<int, int> res;
for (int i = 1; i*i <= n; i++) {
if(n%i == 0){
if(n/i == i)res[i]++;
else res[i]++, res[n/i]++;
}
}
return res;
}
int main(){
int p, q;
std::cin >> p >> q;
int gcd = __gcd(p, q), ans;
p /= gcd;
q /= gcd;
for (int i = 2; i*i <= q; i++) {
int tmp = 0;
for (int j = 2; tmp <= q; j++) {
tmp = pow(i, j);
if(tmp == q){
std::cout << i << std::endl;
return 0;
}
}
}
std::cout << q << std::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 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);
while (1) {
if (result == sqrt(result) * sqrt(result)) {
result = sqrt(result);
} else {
break;
}
}
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 <bits/stdc++.h>
using namespace std;
int gcd(int p, int q) { return p % q == 0 ? q : gcd(q, p % q); }
vector<int> makeprime(int num) {
vector<bool> n(num + 1, true);
n[0] = n[1] = false;
for (int i = 2; i < num + 1; i++) {
if (n[i]) {
for (int j = 2; i * j <= num + 1; j++) {
n[i * j] = false;
}
}
}
vector<int> ret;
for (int i = 2; i < num + 1; i++) {
if (n[i]) ret.push_back(i);
}
return ret;
}
int main() {
long long p, q;
cin >> p >> q;
if (p != 1) q /= gcd(p, q);
long long ans = 1;
vector<int> prime = makeprime(q);
for (int i = 0; i < prime.size(); i++) {
if (q % (long long)prime[i] == 0) {
while (q % (long long)prime[i] == 0) q /= (long long)prime[i];
ans *= (long long)prime[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];
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];
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>
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 (n > 1) {
if (n % i == 0) {
res *= i;
res *= fact(n / i);
while (n % i == 0) n /= i;
}
if (i * i > p) 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;
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;
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 | UNKNOWN | #include <bits/stdc++.h>
int main() {
int p, q;
int i, j, k, n;
int ans = 1;
int num[1000];
j = 0;
for (i = 2; j < 1000; i++) {
for (k = 2; k < i; k++) {
if (i % k == 0) break;
}
if (i == k) {
num[j] = i;
j++;
}
}
scanf("%d%d", &p, &q);
if (p < q)
n = p;
else
n = q;
for (i = 0; num[i] < n; i++) {
while (1) {
if ((p % num[i] == 0) && (q % num[i] == 0)) {
p /= num[i];
q /= num[i];
} else
break;
}
}
for (i = 0; num[i] <= q; i++) {
if (q % num[i] == 0) {
ans *= num[i];
while (q % num[i] == 0) q /= num[i];
}
}
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 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;
map<ll, ll> mp;
for (ll i = 2; i < 40000; ++i) {
for (ll j = 2;; ++j) {
if (pow(i, j) > 1e9) break;
mp[pow(i, j)] = i;
}
}
if (mp[q] == 0)
cout << q << endl;
else
cout << mp[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 (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;
return 0;
}
}
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;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toStr(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
const int MOD = 1000000007;
int gcd(int x, int y) {
if (x < y) {
swap(x, y);
}
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
int main() {
int p, q;
cin >> p >> q;
q /= gcd(p, q);
bool f = true;
while (f) {
f = false;
int s = sqrt(q);
if (s * s == q) {
f = true;
q = s;
}
}
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;
vector<long long> prime;
long long gcd(long long a, long long b) {
if (a == 1) {
return b;
} else {
return gcd(b, a % b);
}
}
void pri() {
vector<bool> state(5001, false);
for (long long i = 2; i < 5000; i++) {
if (!state[i]) {
prime.push_back(i);
for (long long j = 2; i * j < 5000; j++) {
state[i * j] = true;
}
}
}
}
signed main() {
pri();
long long p;
scanf("%lld", &p);
long long q;
scanf("%lld", &q);
while (p && q) {
if (p >= q) {
cout << 2 << endl;
} else {
long long ret = gcd(p, q);
long long ans = 1;
while (ret != 1) {
for (long long i = 0; i < prime.size(); i++) {
if (!(ret % prime[i])) {
ans *= prime[i];
ret /= prime[i];
}
}
}
cout << ans << endl;
}
cin >> p >> q;
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
unsigned int p, q;
vector<int> yakusuu;
int main() {
cin >> p >> q;
if (p != 1) {
for (int i = 1; i <= p / 2; i++) {
if (p % i == 0) {
yakusuu.push_back(i);
}
}
}
yakusuu.push_back(p);
for (int j = 0; j < yakusuu.size(); j++) {
if (q % yakusuu[j] == 0) q = q / yakusuu[j];
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
int n = 0;
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++) {
n = 0;
if(p%j == 0 && q %j == 0) {
qs = q/j;
while(qs % i == 0) {
qs /= i;
n++;
}
if(qs == 1) {
ans = i;
break;
}
}
}
}
System.out.println(ans % Math.pow(buf,n) == 0?ans/(Math.pow(buf, n)):ans);
}
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, mi, ans;
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++) {
int j = i;
while (j < q) {
j *= i;
}
if (j == q) {
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;
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);
}
int main() {
long long a, b;
cin >> a >> b;
long long c = gcd(a, b);
cout << b / c << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
if (r == -1) {
cout << q << endl;
return 0;
}
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 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;
for (int i = 2;; ++i) {
int t = q;
for (;;) {
if (t == 1) {
cout << i << endl;
return 0;
}
if (t % i != 0) break;
t /= i;
}
}
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 <= 1000000000; i++) {
if (check(i)) {
cout << i << endl;
return 0;
}
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
public class Main{
public static void main(String args[]){
try(Scanner sc = new Scanner(System.in)){
long p = sc.nextLong(), q = sc.nextLong();
System.out.println(q/gcd(p,q));
}
}
private static long gcd(long p, long q){
if(p < q) {
return gcd(q, p);
}
if(q==0){
return p;
}
return gcd(q, p%q);
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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() {
int p, q;
cin >> p >> q;
cout << q / gcd(p, q) << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math
p,q = map(int,input().split())
g = math.gcd(p,q)
print(q//g) |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const double EPS = (1e-10);
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
void fast_input() {
cin.tie(0);
ios::sync_with_stdio(false);
}
template <typename T>
T gcd(T a, T b) {
return b != 0 ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
return a * b / gcd(a, b);
}
vector<pair<int, int>> prime_factorization(int n) {
int k = n;
vector<pair<int, int>> ret;
for (int i = 2; i <= sqrt(n); i++) {
int cnt = 0;
while (k % i == 0) {
k /= i;
cnt++;
}
if (cnt) ret.push_back({i, cnt});
}
if (k > 1) ret.push_back({k, 1});
return ret;
}
int main(void) {
int p, q;
cin >> p >> q;
while (gcd(p, q) != 1) {
int tmp = gcd(p, q);
p /= tmp;
q /= tmp;
}
int cnt;
vector<pair<int, int>> qfac = prime_factorization(q);
for (int i = 0; i < qfac.size(); i++) {
if (i == 0)
cnt = qfac[i].second;
else if (cnt != qfac[i].second) {
cnt = -1;
}
}
int ans = 1;
if (cnt != -1) {
for (int i = 0; i < qfac.size(); i++) {
ans *= qfac[i].first;
}
} else {
for (int i = 0; i < qfac.size(); i++) {
for (int j = 0; j < qfac[i].second; j++) {
ans *= qfac[i].first;
}
}
}
cout << ans << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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 << 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;
for (long long i = 2; i * i <= q; i++) {
if (p % i == 0 && q % i == 0) {
do {
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 | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, pre_limit, limit;
scanf("%d %d", &p, &q);
pre_limit = sqrt(q);
for (int i = 2; i <= pre_limit; i++) {
while (p % i == 0 && q % i == 0) {
p /= i;
q /= i;
}
}
limit = sqrt(q);
int ans = 1;
for (int i = 2; i <= limit; i++) {
if (q % i == 0) {
ans *= i;
while (q % i == 0) q /= i;
}
}
ans *= q;
printf("%d\n", ans);
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | 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 = 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 = 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 yaku(int a, int b) {
if (a % b == 0) {
return b;
}
return yaku(b, a % b);
}
int main() {
int a, b;
cin >> a >> b;
int n = yaku(a, b);
a /= n;
b /= n;
int ans = 1;
for (int i = 2; b != 1; i++) {
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 | java | import java.util.*;
public class Main{
public static void main(String args[]){
try(Scanner sc = new Scanner(System.in)){
long p = sc.nextLong(), q = sc.nextLong();
long memo = q/gcd(p,q);
long ans = memo;
int i = 0;
long[] X = new long[10000];
long x = 2;
while(memo!=1){
while(memo%x==0){
X[i++]=x;
memo/=x;
}
x++;
if(x*x>memo){
X[i++]=memo;
break;
}
}
if(X[0]==X[i-1]){
System.out.println(X[0]);
} else {
System.out.println(ans);
}
}
}
private static long gcd(long p, long q){
if(p < q) {
return gcd(q, p);
}
if(q==0){
return p;
}
return gcd(q, p%q);
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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));
}
}
int main() {
int p, q;
cin >> p >> q;
cout << q / gcd(p, q) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int p,q;
cin>>p>>q;
p=q/__gcd(p,q);
int f=0;
for(int i=2;i*i<=p;i++){
if(p%i)continue;
f=i;
break;
}
if(f==0){
cout<<p<<endl;
return 0;
}
int t=p;
while(t%f==0&&t!=1)t/=f;
if(t==1)cout<<f<<endl;
else cout<<p<<endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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;
int gcdqp = gcd(q, p);
if (p == gcdqp) cout << 1 << endl;
cout << q / gcd(q, p) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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 = p;
int m = q;
int l = gcd(n, m);
while (l != 1) {
n = n / l;
m = m / l;
l = gcd(n, m);
}
cout << m << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int euclid(int x, int y) {
int t;
while (x % y) {
x %= y;
t = x;
x = y;
y = t;
}
return y;
}
int main() {
int p, q, n, m, t = 2, ans = 1;
cin >> p >> q;
n = q / euclid(p, q);
m = n;
map<int, int> f;
while (n > 1) {
if (!(n % t)) {
n /= t;
f[t] = 1;
}
while (!(n % t)) {
++f[t];
n /= t;
}
++t;
}
m = q;
for (auto itr = f.begin(); itr != f.end(); ++itr) m = min(m, itr->second);
for (auto itr = f.begin(); itr != f.end(); ++itr) {
m = euclid(m, itr->second);
}
for (auto itr = f.begin(); itr != f.end(); ++itr) {
for (int i = 0; i < itr->second / m; ++i) {
ans *= itr->first;
}
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.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<=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>
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 == 0 && j == 1)
p /= i;
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;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using ll = long long;
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a * b / gcd(a, b); }
class Eratosthenes {
public:
int n, sqlim;
vector<bool> prime;
Eratosthenes(int N) : n(N + 1) {
sqlim = (int)ceil(sqrt(n));
prime = vector<bool>(n, 1);
prime[0] = prime[1] = 0;
for (int i = 2; i <= sqlim; i++)
if (prime[i])
for (int j = i * i; j <= n; j += i) prime[j] = 0;
}
vector<int> primeArray(int s = 0, int l = 10000) {
vi ret;
for (int i = s; ret.size() != l; i++)
if (prime[i]) ret.push_back(i);
return ret;
}
};
int main() {
int p, q;
cin >> p >> q;
q /= gcd(p, q);
int ans = 0;
for (int i = 2; i * i <= q; i++) {
if (q % i == 0) {
ans = i;
q /= i;
i--;
}
}
cout << ans << endl;
return 0;
}
|
Subsets and Splits