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;
int GCD(int a, int b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
int p, q;
cin >> p >> q;
q /= GCD(p, q);
int ans = q;
map<int, int> mpa;
for (int i = 2; i * i <= q; i++) {
while (q % i == 0) {
mpa[i]++;
q /= i;
}
}
if (q != 1) mpa[q]++;
map<int, int>::iterator it;
if (mpa.size() == 1)
ans = mpa.begin()->first;
else {
int pow = mpa.begin()->first;
for (it = mpa.begin(); it != mpa.end(); it++) {
if (it == mpa.begin()) continue;
pow = GCD(pow, it->second);
}
if (pow >= 2) {
int num = 1;
for (it = mpa.begin(); it != mpa.end(); it++) {
for (int i = 1; i <= it->second / pow; i++) {
num *= it->first;
}
}
ans = num;
}
}
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>
long long int gcd(long long int p, long long int q) {
if (!q) return p;
if (q > p) return gcd(q, p);
return gcd(q, p % q);
}
int main(void) {
long long int p, q;
scanf("%lld%lld", &p, &q);
long long int g = gcd(p, q);
p /= g;
q /= g;
long long int b = 1;
for (long long int i = 2; q - 1; i++)
if (!(q % i)) {
b *= i;
while (!(q % i)) q /= i;
}
printf("%lld\n", b);
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int P, Q;
bool p[100000000];
vector<int> v;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long solve() {
long long ans = 1;
for (int i = ((int)0); i < ((int)v.size()); i++)
if (Q % v[i] == 0) ans *= v[i];
if (ans == 1) ans *= Q;
return ans;
}
int main(void) {
for (int i = ((int)0); i < ((int)100000000); i++) p[i] = true;
p[0] = p[1] = false;
for (int i = ((int)0); i < ((int)100000000); i++)
if (p[i])
for (int j = i * 2; j < 100000000; j += i) p[j] = false;
for (int i = ((int)0); i < ((int)100000000); i++)
if (p[i]) v.push_back(i);
cin >> P >> Q;
Q = Q / gcd(P, Q);
cout << solve() << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
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 | import math
p, q = map(int, input().split())
g = math.gcd(p, q)
p //= g
q //= g
ret = q
for b in range(1, 40000):
if b ** 1000 * p % q == 0:
ret = min(ret, b)
print(ret) |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | prime = [2]
def check(x):
for i in prime:
if x % i ==0:
return False
elif x < i * i:
break
return True
def set():
for i in range(3,10**5,2):
if check(i):
prime.append(i)
set()
#print(prime)
p,q = [int(i) for i in input().split(' ')]
for i in prime:
while True:
if p % i ==0 and q % i == 0:
p = p//i
q = q//i
else:
break
ans = 1
for i in prime:
if q % i == 0:
# print(q,i)
q = q // i
ans *= i
while q % i ==0:
q = q // i
print(ans)
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long int p, q;
cin >> p >> q;
q /= gcd(p, q);
double n = sqrt(q);
for (long long int i = 2; i <= n; i++) {
long long int x = i;
while (x <= q) {
if (x == q) {
cout << i << endl;
return 0;
}
x *= i;
}
}
cout << q << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
solve();
}
public static void solve(){
Scanner sc = new Scanner(System.in);
int p = sc.nextInt();
int q = sc.nextInt();
if(q%p==0){
q /= p;
p = 1;
}
boolean[] judge = new boolean[(int)Math.sqrt(1000000000)+5];
Arrays.fill(judge,true);
judge[0] = false;
judge[1] = false;
for(int i=2;i<judge.length;i++){
if(judge[i]){
if(p%i==0 && q%i==0){
p /= i;
q /= i;
i--;
}
for(int j=i*2;j<judge.length;j+=i){
judge[j] = false;
}
}
}
for(int i=2;i<judge.length;i++){
if(judge[i] && q%(i*i)==0){
q /= i;
i--;
}
}
System.out.println(q);
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
long p = scn.nextLong(), q = scn.nextLong();
scn.close();
long qs;
long ans = q;
long bp = p,bq = q,buf = p;
while(bq % bp != 0) {
buf = bq % bp;
bq = bp;
bp = buf;
}
for(int i = 2;i <= Math.sqrt(q);i++) {
for(int j = 1;j <= buf;j++) {
if(p%j == 0 && q %j == 0) {
qs = q/j;
while(qs % i == 0) {
qs /= i;
}
if(qs == 1) {
ans = i;
break;
}
}
}
}
System.out.println(ans);
}
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++) v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
while (a % b != 0) {
a %= b;
swap(a, b);
}
return b;
}
int main() {
map<int, int> mpii;
for (int i = (int)(1); i < (int)(40000); ++i) mpii[i * i] = i;
int p, q;
cin >> p >> q;
q /= gcd(p, q);
set<int> soinsu;
for (int i = (int)(2); i < (int)(q + 1); ++i) {
while (q % i == 0) {
q /= i;
soinsu.insert(i);
}
}
long long ans = 1;
for (int a : soinsu) ans *= a;
cout << ans << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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(INF,true);
loop(i,2,INF)
if(prime[i])
for(j=2;i*j<=INF;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;
long long p, q;
long long stol(long long a, long long b) {
if (a < b) swap(a, b);
if (a % b == 0) return b;
return stol(b, a % b);
}
signed main() {
cin >> p >> q;
cout << q / stol(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 | java | import java.util.Scanner;
import java.util.ArrayList;
public class Main {
Scanner sc = new Scanner(System.in);
public void run(){
int p = sc.nextInt();
int q = sc.nextInt();
calc(p, q);
}
public void calc(int p, int q){
int a = q;
int b = p;
int max = 0;
while(true){
int c = a % b;
if(c == 0){
max = b;
break;
}
else{
a = b;
b = c;
}
}
q = q / max;
int ans = -1;
char[] memo = new char[100000];
for(int i = 2; i < Math.min(q, 100000); i++){
if(memo[i] == 0){
long k = i;
while(true){
if(k == q) {
ans = i;
break;
}
else if(k > q || k >= 100000) {
break;
}
else{
memo[(int)k] = 1;
k = k * i;
}
}
}
if(ans != -1) break;
}
if(ans == -1) ans = q;
System.out.println(ans);
}
public static void main(String[] args){
new Main().run();
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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;
cin >> p >> q;
cout << q / euclid(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;
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
typedef pair<int,int> pi;
vector<pi> f(int n)
{
int t=n;
vector<pi> ret;
for(int i=2; i*i<=n; ++i)
{
if(t%i==0)
{
pi add(i,0);
while(t%i==0)
{
++add.se;
t/=i;
}
ret.pb(add);
}
}
if(t>1) ret.pb(pi(t,1));
return ret;
}
int main()
{
int p,q;
cin >>p >>q;
int g=__gcd(p,q);
p/=g;
q/=g;
vector<pi> d=f(q);
int ans=q;
if(d.size()==1) ans=d[0].fi;
cout << ans << endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int p, q;
cin >> p >> q;
q /= gcd(p, q);
for (int i = 2; i < 32000; i++) {
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;
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);
}
bool check(long long q, long long i) {
while (q % i == 0) {
q /= i;
if (q == 1) {
return true;
}
}
return false;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
long long p, q;
cin >> p >> q;
long long g = gcd(p, q);
p /= g;
q /= g;
for (long long i = (2); i < (100000); i++) {
if (check(q, i)) {
cout << i << 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);
int x = gcd(q, p);
p /= x;
q /= x;
for (int i = 2; i <= q; i++) {
int m = q;
while (!(m % i)) m /= i;
if (m == 1) {
printf("%d\n", i);
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;
int main(){
int q,p,t,ans=1,i,j,c=0;
cin>>q>>p;t=p;
p/=__gcd(q,p);
if(p!=t&&q!=1)for(i=2;i*i<=t;i++){
if(p%i==0){
p/=i;
ans*=i;
i--;
}
}
else ans=t;
cout<<ans<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b > a) {
int t = b;
b = a;
a = t;
}
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main(int argc, char const *argv[]) {
int a, b;
cin >> a >> b;
cout << b / gcd(a, b) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, a;
set<int> s;
cin >> p >> q;
a = q;
for (int i = 2; i * i < q; i++) {
s.clear();
int r = p;
while (r != 0) {
if (s.count(r)) break;
s.insert(r);
r *= i;
r %= q;
}
if (r == 0) {
a = i;
break;
}
}
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 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;
}
signed main() {
long long p, q;
cin >> p >> q;
if (p != 1) q /= gcd(p, q);
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(){
long long p,q;
cin >> p >> q;
int va=q;
int ans=0;
for(long long i=2;i*i<=va;i++){
if(ans!=0)
break;
if(q%i==0){
ans=-1;
while(q%i==0){
q/=i;
//cout << q << endl;
}
if(q==1)
ans=i;
}
}
if(ans!=0&&ans!=-1){
//cout << "=============" << q << endl;
cout << ans << endl;
}
else{
q=va;
for(long long i=2;i*i<=va;i++){
if(p==1)break;
while(p%i==0&&q%i==0){
p/=i;
q/=i;
}
}
cout << q << endl;
/*for(long long i=2;i*i<=va;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;
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];
while (q % now == 0 && p % now == 0) q /= now, p /= now;
}
int ans = 1, qq = q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (q % now == 0) ans *= now;
while (q % now == 0) q /= now;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(x * a, y * a); }
Point operator/(double a) { return Point(x / a, y / a); }
double absv() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);
}
};
struct Segment {
Point p1, p2;
};
double hen(Point a) {
if (fabs(a.x) < (1e-10) && a.y > 0)
return acos(0);
else if (fabs(a.x) < (1e-10) && a.y < 0)
return 3 * acos(0);
else if (fabs(a.y) < (1e-10) && a.x < 0)
return 2 * acos(0);
else if (fabs(a.y) < (1e-10) && a.x > 0)
return 0.0;
else if (a.y > 0)
return acos(a.x / a.absv());
else
return 2 * acos(0) + acos(-a.x / a.absv());
}
string itos(long long i) {
ostringstream s;
s << i;
return s.str();
}
long long gcd(long long v, long long b) {
if (v > b) return gcd(b, v);
if (v == b) return b;
if (b % v == 0) return v;
return gcd(v, b % v);
}
double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
double distans(double x1, double y1, double x2, double y2) {
double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
return sqrt(rr);
}
long long dp[1010][300] = {0};
long long L[201][201], S[201][201];
signed main() {
long long n, m;
cin >> n >> m;
cout << m / gcd(n, 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;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384
int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
vl primeFactorVec(ll n) {
vl ret;
for(ll i=2;i*i<=n;i++){
if(n%i==0){ret.push_back(i);while(n%i==0){ret.push_back(i);n/=i;}};
}
if(n>1) ret.push_back(n);
return ret;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll p,q;
cin>>p>>q;
vl v=primeFactorVec(p);
for(auto x:v){
if(q%x==0)q/=x;
}
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 main() {
long long p, q;
cin >> p >> q;
int va = q;
int ans = 0;
for (long long i = 2; i * i <= va; i++) {
if (ans != 0) break;
if (q % i == 0) {
ans = -1;
while (q % i == 0) {
q /= i;
}
if (q == 1) ans = i;
}
}
if (ans != 0 && ans != -1) {
cout << ans << endl;
} else {
q = va;
for (long long i = 2; i * i <= va; i++) {
if (p == 1) break;
while (p % i == 0 && q % i == 0) {
p /= i;
q /= i;
}
}
cout << q << endl;
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
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++) {
va = Q;
while (Q % i == 0 && P < (Q / i)) Q /= i;
if (Q == i)
break;
else
Q = va;
}
cout << Q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
int p, q;
cin >> p >> q;
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;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
bool isPrime[100000];
int main() {
int p, q;
cin >> p >> q;
int d = gcd(p, q);
q /= d;
fill(isPrime, isPrime + 100000, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i < 100000; i++) {
if (!isPrime[i]) continue;
for (int k = 2; i * k < 100000; k++) isPrime[k * i] = false;
}
int r = -1;
vector<pair<int, int> > V;
for (int i = 2; i <= q && i < 100000; i++) {
if (!isPrime[i]) continue;
if (q % i == 0) {
int cnt = 0;
while (q % i == 0) {
cnt++;
q /= i;
}
if (r == -1) {
r = cnt;
} else {
r = gcd(r, cnt);
}
V.emplace_back(i, cnt);
}
}
int ans = 1;
for (auto v : V) {
int k = v.first;
for (int i = 0; i < v.second / r; i++) ans *= k;
}
cout << ans << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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);
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 std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set;
using std::setprecision;
using std::stack;
using std::string;
using std::vector;
int gcd(int p, int q) {
int temp;
if (q == 0) {
return p;
} else {
temp = p % q;
p = q;
q = temp;
return gcd(p, q);
}
return 0;
}
bool prime_check(int number) {
if (number == 2) {
return true;
} else if (number % 2 == 0) {
return false;
}
for (int i = 3; i * i <= number; i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
int main(void) {
int p;
int q;
int ans = 1;
cin >> p >> q;
q /= gcd(p, q);
for (int i = 2; i <= q; i++) {
if (prime_check(i) == true && q % i == 0) {
ans *= i;
}
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int main() {
int p, q, n, res = 1;
cin >> p >> q;
n = q / GCD(p, q);
for (int i = 2; i < sqrt(n) + 2; i++) {
if (n % i == 0) {
res *= i;
}
}
if (res == 1) res = 2;
cout << res << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | 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++) {
va = Q;
int count = 0;
while (Q % i == 0) {
count++;
Q /= i;
}
if (count == 2) {
va /= i;
}
Q = va;
}
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);
signed main() {
long long p;
scanf("%lld", &p);
;
long long q;
scanf("%lld", &q);
;
while (p && q) {
long long base = gcd(p, q);
q /= base;
for (long long i = 2; i * i <= q; i++) {
if (!(q % i)) {
long long ret = q / i;
while (!(ret % i)) {
q /= i;
ret /= i;
}
}
}
cout << q << endl;
cin >> p >> q;
}
return 0;
}
long long gcd(long long a, long long b) {
if (!b) {
return a;
} else {
gcd(b, a % b);
}
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
uint32_t gcd(uint32_t a, uint32_t b) {
if (b > a) return gcd(b, a);
if (b == 0) return a;
return gcd(b, a % b);
}
int32_t main() {
uint32_t p, q;
cin >> p >> q;
uint32_t g = gcd(p, q);
p /= g;
q /= g;
for (uint32_t i = 2; i <= q; i++) {
uint32_t tmp = q;
while (tmp > 1) {
if (tmp % i == 0) {
tmp /= i;
} else {
break;
}
}
if (tmp == 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 | java | import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static void main(String args[]) {
ArrayList<Long> yaku = new ArrayList<Long>();
Scanner scn = new Scanner(System.in);
long p = scn.nextLong(), q = scn.nextLong();
scn.close();
long qs;
long ans = q;
long bp = p,bq = q,buf = p;
long r;
while(bq % bp != 0) {
buf = bq % bp;
bq = bp;
bp = buf;
}
for(long i = 1;i <= Math.sqrt(buf);i++) {
if(buf%i==0) {
yaku.add(i);
yaku.add(buf/i);
}
}
ans = q/buf;
for(int i = 0;i < yaku.size();i++) {
qs = q/yaku.get(i);
for(int j = 30;j > 1;j--) {
r = Math.round(Math.pow(qs,1/(double)(j)));
if(Math.pow(r,j)==qs)ans = Math.min(ans, j);
}
}
System.out.println(ans);
}
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int p, q, r = 1;
int main() {
scanf("%d%d", &p, &q);
q = q / _gcd(p, q);
for(int i = 2; i * i <= q; i++) {
if(q % i == 0) {
r *= i;
while(q % i == 0) q /= i;
}
}
printf("%d\n", r * 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;
long long solve(long long a, long long b) {
int 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;
int i = 2, j = 0, temp = q;
while (temp != 1) {
if (temp % i == 0) {
temp /= i;
prime[j]++;
} else {
if (i == 2)
i = 3;
else
i += 2;
if (prime[j] > 0) j++;
}
}
sort(prime.begin(), prime.begin() + j);
if (prime[0] == 1)
;
else {
int k = 2;
while (prime[0] != 1 && prime[0] >= k) {
if (prime[0] % k == 0) {
int all = 1;
for (int l = 0; l < j; l++) {
if (prime[l] % k != 0) {
if (k == 2)
k = 3;
else
k += 2;
all = 0;
break;
}
}
if (all = 1) {
double kk;
kk = k;
q = pow(q, 1 / kk);
for (int l = 0; l <= j; l++) prime[l] /= k;
}
} else {
if (k == 2)
k = 3;
else
k += 2;
}
}
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int p,q;
cin>>p>>q;
p=q/__gcd(p,q);
for(int i=2;i*i<=p;i++){
if(p%i)continue;
int t=p;
while(t%i==0)t/=i;
if(t==1){
cout<<i<<endl;
return 0;
}
}
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<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
int i,j;
int p,q;
cin>>p>>q;
q=q/__gcd(p,q);
ll ans=1;
for(i=2;i<=q;i++)if(q%i==0){
ans*=i;
while(q%i==0)q/=i;
}
cout<<ans<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set;
using std::setprecision;
using std::stack;
using std::string;
using std::vector;
int gcd(int p, int q) {
int temp;
if (q == 0) {
return p;
} else {
temp = p % q;
p = q;
q = temp;
return gcd(p, q);
}
return 0;
}
bool prime_check(int number) {
if (number == 2) {
return true;
} else if (number % 2 == 0) {
return false;
}
for (int i = 3; i * i <= number; i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
int main(void) {
int p;
int q;
cin >> p >> q;
q /= gcd(p, q);
vector<bool> table(1e09, true);
for (int i = 2; i * i < 1e09; i++) {
if (table[i] == true) {
int times = 2;
while (i * times < 1e09) {
table[i * times] = false;
times++;
}
}
}
int ans = 1;
for (int i = 2; i <= q; i++) {
if (table[i] == true && q % i == 0) {
ans *= i;
}
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using 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 < 10000; ++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;
long long int gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
vector<bool> prime(1000000000 + 1, true);
void make(long long int M) {
prime[0] = prime[1] = false;
for (long long int i = 2; i * i < M + 1; i++) {
if (prime[i]) {
long long int j = 2;
while (i * j < M + 1) {
prime[i * j] = false;
j++;
}
}
}
return;
}
int main() {
long long int a, b;
cin >> a >> b;
make(max(a, b));
long long int c = b / gcd(a, b);
long long int ans = 1;
for (long long int i = 2; i <= max(a, b); i++) {
if (prime[i] && c % i == 0) {
ans *= i;
}
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main(){
int q,p,t,ans=1,i,j,c;
cin>>q>>p;t=p;
p/=__gcd(q,p);
for(i=2;i*i<=t*2;i++){
if(p%i==0){
p/=i;
ans*=i;
i--;
}
}
cout<<ans<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main(void) {
int p, q;
scanf("%d %d", &p, &q);
printf("%d\n", gcd(p, q));
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
long long p, q;
cin >> p >> q;
int va = q;
int ans = 0;
for (long long i = 2; i * i <= va; i++) {
if (ans != 0) break;
if (q % i == 0) {
ans = -1;
while (q % i == 0) {
q /= i;
}
if (q == 1) ans = i;
}
}
if (ans != 0 && ans != -1) {
cout << ans << endl;
} else {
q = va;
for (long long i = 2; i * i <= va; i++) {
if (p == 1) break;
while (p % i == 0 && q % i == 0) {
p /= i;
q /= i;
}
}
for (long long i = 2; i * i <= va; i++) {
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;
int main(){
int q,p,t,ans=1,i,j,c=0;
cin>>q>>p;t=p;
p/=__gcd(q,p);
if(p!=t||q==1)for(i=2;i*i<=t;i++){
if(p%i==0){
p/=i;
if(ans%i)ans*=i;
i--;
}
}
else ans=t;
cout<<ans<<endl;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return gcd(b, a % b);
}
signed main() {
long long p, q;
cin >> p >> q;
cout << max((long long)2, q / gcd(p, q)) << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int in(void) {
int i;
scanf("%d", &i);
return i;
}
long long llin(void) {
long long i;
scanf("%lld", &i);
return i;
}
void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int calc(int x) {
int i, j;
for (i = 2; i * i <= x; i++) {
if (x % i == 0) {
for (j = 1; j <= x; j *= i) {
if (j == x) {
x = i;
break;
}
}
}
}
return x;
}
int main(void) {
int p = in(), q = in();
int i, j, a, b, c;
a = q / gcd(p, q);
b = calc(q);
c = calc(q / gcd(p, q));
print(min(a, min(b, c)));
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 lcm(int a, int b) {
if (a < b) {
swap(a, b);
}
if (!b) {
return a;
}
return lcm(b, a % b);
}
int main() {
int i, p, q, lc, cl;
double lm, buf, df, m;
cin >> p >> q;
lc = lcm(p, q);
p /= lc;
q /= lc;
lm = log(q) / log(2);
cl = (int)lm + 1;
for (i = 1; i <= cl; i++) {
buf = pow(q, (double)1 / i);
df = (int)buf + 1 - buf;
if (df == 1 || df < 0.0001) {
m = buf;
}
}
cout << 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 p, q;
vector<int> primes;
bool check(int a) {
int aa = a;
while (a <= q) {
if (q % a == 0) return 1;
a *= aa;
}
return 0;
}
bool t[10000000];
void eratosu() {
t[1] = 1;
for (int i = 2; i <= 10000000; i++) {
if (t[i] == 0) {
primes.push_back(i);
for (int j = i * 2; j <= 10000000; j += i) t[j] = 1;
}
}
}
int main() {
eratosu();
cin >> p >> q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
while (p % now == 0 && q % now == 0) p /= now, q /= now;
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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);
a /= c;
b /= c;
for (int i = 2; i < 111111; i++) {
if (b % i == 0) {
long long tmp = b;
while (tmp % i == 0) tmp /= i;
if (tmp == 1) {
cout << i << endl;
return 0;
}
}
}
cout << b << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | import math
f=lambda n:min(int(i) for i in (round(n**(1/i),10) for i in range(1,int(math.log(n,2))+2)) if int(i)==i)
p,q=map(int,input().split())
if f(q)==q:
e=math.gcd(p,q)
q/=e
e=f(q)
if f(q)!=q:
q=e
print(int(q))
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
import java.util.ArrayList;
public class Main {
Scanner sc = new Scanner(System.in);
public void run(){
int p = sc.nextInt();
int q = sc.nextInt();
calc(p, q);
}
public void calc(int p, int q){
int a = q;
int b = p;
int max = 0;
while(true){
int c = a % b;
if(c == 0){
max = b;
break;
}
else{
a = b;
b = c;
}
}
q = q / max;
int ans = -1;
char[] memo = new char[100000];
for(int i = 2; i < Math.min(q, 100000); i++){
if(memo[i] == 0){
long k = i;
while(true){
if(k > q) break;
else if(k == q) {
ans = i;
break;
}
else{
memo[(int)k] = 1;
k = k * i;
}
}
}
if(ans != -1) break;
}
if(ans == -1) ans = q;
System.out.println(ans);
}
public static void main(String[] args){
new Main().run();
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
map<int, int> mp;
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 i = 2;
while (i * i <= 1000000000) {
mp[i * i] = i;
i++;
}
while (mp[q] != 0) {
q = mp[q];
}
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;
int main() {
int a, b;
cin >> a >> b;
while (1) {
int stat = 0;
for (int i = 2; i <= sqrt(max(a, b)); i++) {
if (a % i == 0 && b % i == 0) {
stat = 1;
a /= i;
b /= i;
break;
}
}
if (stat == 0) break;
}
cout << b << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q;
cin >> p >> q;
for (int i = 2; i < 1e9; i += 2) {
if (q % i == 0 && p % (q / i) == 0) {
cout << i << endl;
break;
}
if (i == 2) 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 main() {
int p, q, use;
int so[40000] = {0};
cin >> p >> q;
use = q;
int a;
while (q % p != 0) {
a = q % p;
q = p;
p = a;
}
use /= p;
q = use;
vector<int> sonaka;
for (int i = 2; i < 20000; i++)
if (so[i] == 0) {
sonaka.push_back(i);
for (int j = i * 2; j < 40000; j += i) so[j] = 1;
}
int result = 1;
for (int i = 0; sonaka[i] <= use && i < sonaka.size(); i++) {
if (use % sonaka[i] == 0) {
result *= sonaka[i];
while (use % sonaka[i] == 0) use /= sonaka[i];
}
}
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 | python3 | from math import gcd
p,q=[int(i) for i in input().split()]
g = gcd(p,q)
q//=g
prime=[]
p=2
while p<q:
if q%p==0:
prime.append(p)
q//=p
else:
p+=1
if q!=1:
prime.append(q)
prime=set(prime)
if len(prime)==0:
print(q)
else:
res=1
for p in prime:
res*=p
print(res)
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | #include <bits/stdc++.h>
int in(void) {
int i;
scanf("%d", &i);
return i;
}
long long llin(void) {
long long i;
scanf("%lld", &i);
return i;
}
void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int main(void) {
int p = in(), q = in();
int i, j, a, b;
a = q / gcd(p, q);
b = q;
for (i = 2; i * i <= b; i++) {
if (b % i == 0) {
for (j = 1; j <= b; j *= i) {
if (j == b) {
b = i;
break;
}
}
}
}
print(min(a, b));
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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);
}
vector<int> primeFactorization(int n) {
int k = n;
vector<int> ret;
for (int i = 2; i <= sqrt(n); i++) {
while (k % i == 0) {
ret.push_back(i);
k /= i;
}
}
if (k > 1) ret.push_back(k);
return ret;
}
int main(void) {
int p, q;
cin >> p >> q;
vector<int> pfac = primeFactorization(p);
vector<int> qfac = primeFactorization(q);
for (auto &i : pfac) {
for (auto &j : qfac) {
if (i == j) {
i = j = 1;
break;
}
}
}
int ans = 1;
for (auto &i : qfac) {
ans *= i;
}
cout << ans << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::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 % i == 0) {
tgt /= i;
}
if (tgt == 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;
int GCD(int a, int b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
int p, q;
cin >> p >> q;
q /= GCD(p, q);
int ans = q;
set<int> sta;
for (int i = 2; i * i <= q; i++) {
if (q % i == 0) sta.insert(i);
}
set<int>::iterator it;
for (it = sta.begin(); it != sta.end(); it++) {
int num = 1;
while (num < q) num *= (*it);
if (num == q && (*it) < ans) ans = (*it);
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
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;
if(c < 0) ans *= i;
}
if(q != 1) ans *= q;
cout << ans << endl;
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int gcd(int n, int m) {
if (n % m == 0) {
return m;
} else {
return gcd(m, n % m);
}
}
int main(void) {
int p, q;
cin >> p >> q;
int n = q;
int m = p;
int l = gcd(n, m);
while (l != 1) {
n = n / l;
m = m / l;
l = gcd(n, m);
}
if ((int)sqrt(n) == sqrt(n)) {
n = sqrt(n);
}
if (q % 2 == 0) {
while (n % 2 != 1) {
n = n / 2;
}
cout << 2 * n << endl;
} else {
cout << n << endl;
}
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, a;
set<int> s;
cin >> p >> q;
a = q;
for (int i = 2; i < q / 2; i++) {
s.clear();
int r = p;
while (r != 0) {
if (s.count(r)) break;
s.insert(r);
r *= i;
r %= q;
}
if (r == 0) {
a = i;
break;
}
}
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;
long long int LCM(long long int a, long long int b) {
long long int dummy1, dummy2, dummy;
dummy1 = max(a, b);
dummy2 = min(a, b);
while (true) {
dummy = dummy1 % dummy2;
dummy1 = dummy2;
dummy2 = dummy;
if (dummy == 0) {
break;
}
}
return (a / dummy1) * (b / dummy1) * dummy1;
}
long long int GCD(long long int a, long long int b) {
long long int dummy1, dummy2, dummy;
dummy1 = max(a, b);
dummy2 = min(a, b);
while (true) {
dummy = dummy1 % dummy2;
dummy1 = dummy2;
dummy2 = dummy;
if (dummy == 0) {
break;
}
}
return dummy1;
}
int main() {
long long int a, b;
cin >> a >> b;
cout << b / GCD(a, b) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, x, test;
cin >> p >> q;
if (p < q) swap(p, q);
test = p;
while (1) {
if (p % q != 0) {
x = p % q;
p = q;
q = x;
continue;
}
break;
}
int tmp = test / q;
int ans = tmp;
for (int i = 2; i <= sqrt(tmp) + 1; ++i) {
if (tmp % i == 0) {
int a = tmp;
while (a) {
if (a % i)
break;
else if (a / i == 1)
ans = i;
a /= i;
}
if (ans != 1) 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 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;
bool prime_check = true;
for (ll i = 2; i * i <= q; ++i) {
if (q % i == 0) prime_check = false;
}
if (prime_check) {
cout << q << endl;
return 0;
}
for (ll i = 2;; ++i) {
ll 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 main(){
int p,q;
cin>>p>>q;
p=q/__gcd(p,q);
int f=0;
for(int i=2;i*1<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;
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);
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
int 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);
int x = gcd(q, p);
p /= x;
q /= x;
bool ok = true;
for (int i = 2; i <= sqrt(q); i++) {
int m = q;
while (!(m % i)) m /= i;
if (m == 1) {
printf("%d\n", i);
ok = false;
break;
}
}
if (ok) printf("%d\n", 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 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)
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;
int p, q;
vector<int> yakusuu;
int main() {
cin >> p >> q;
for (int i = 2; i <= p / 2; i++) {
if (p % i == 0) {
yakusuu.push_back(i);
}
}
for (int j = 0; j < yakusuu.size(); j++) {
if (q % yakusuu[j] == 0) q = q / yakusuu[j];
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(){
int p,q;
cin>>p>>q;
int a=__gcd(p,q);
p/=a,q/=a;
for(int i=2;i*i<=q;i++){
if(q%i!=0)continue;
while((q/i)%i==0)q/=i;
while((q/(q/i))%(q/i)==0)q/=(q/i);
}
cout <<q<<endl;
return 0;
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, use;
int so[40000] = {0};
cin >> p >> q;
use = q;
int a;
while (q % p) {
a = q % p;
q = p;
p = a;
}
use /= p;
vector<int> sonaka;
for (int i = 2; i < 40000; i++)
if (!so[i]) {
sonaka.push_back(i);
for (int j = i * 2; j < 40000; j += i) so[j] = 1;
}
int result = 1;
for (int i = 0; sonaka[i] <= use && i < sonaka.size(); i++)
if (!use % sonaka[i]) {
result *= sonaka[i];
while (!use % sonaka[i]) use /= sonaka[i];
}
cout << result * use << 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;
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;
if (p / g != 1) {
cout << qq << endl;
} else {
for (uint32_t i = 2; i <= qq; 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>
const int INF = 100000000;
using namespace std;
int gcd(int x, int y) {
int r;
if (x < y) swap(x, y);
while (y > 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
int main() {
int p, q;
cin >> p >> q;
int x = gcd(p, q);
q /= x;
bool f = false;
for (int i = 2; i * i <= 1000000000; i++) {
int temp = q;
while (temp % i == 0) {
if (temp == i) f = true;
temp /= i;
}
if (f) {
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;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int p, q;
cin >> p >> q;
int r = gcd(q, p);
p /= r;
q /= r;
int ans = 1;
for (int i = 2; i * i <= q; i++) {
if (q % i != 0) continue;
ans *= i;
while (q % i == 0) q /= i;
}
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 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++) {
va = Q;
int count = 0;
while (Q % i == 0 && Q / i != 1) {
count++;
Q /= i;
}
if (Q == i) break;
if (count == 2) {
va /= i;
}
Q = va;
}
cout << Q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long inf = 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);
}
bool check(long long q, long long i) {
while (q % i == 0) {
q /= i;
if (q == 1) {
return true;
}
}
return false;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
long long p, q;
cin >> p >> q;
p /= gcd(p, q);
q /= gcd(p, q);
for (long long i = (2); i < (100000); i++) {
if (check(q, i)) {
cout << i << 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();
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 | UNKNOWN | #include <bits/stdc++.h>
int gcd(int a, int b) {
if (b == 0) return a;
if (a > b) return gcd(b, a % b);
return gcd(a, b % a);
}
int main(void) {
int p, q, g, f2, f5, t;
scanf("%d %d", &p, &q);
g = gcd(p, q);
q /= g;
f2 = f5 = 0;
t = q;
while (t % 2 == 0) {
f2 = 1;
t /= 2;
}
if (t == 1) {
printf("2\n");
return 0;
}
t = q;
while (t % 5 == 0) {
f5 = 1;
t /= 5;
}
if (t == 1) {
printf("5\n");
return 0;
}
if (f2 && f5)
printf("10\n");
else
printf("%d\n", 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>
int pr[50847534];
int x = 0;
int nextpr(int p) {
int nxp = p + 2;
int i;
int ok = 1;
pr[x] = p;
x++;
if (p == 2) return 3;
while (1) {
for (i = 0; pr[i] * pr[i] <= nxp; i++) {
ok = 1;
if (nxp % pr[i] == 0) {
ok = 0;
break;
}
}
if (ok) {
return nxp;
} else {
nxp += 2;
}
}
}
int main() {
int p, q, m, oriq, ans = 1;
scanf("%d %d", &p, &q);
oriq = q;
m = p % q;
while (m) {
p = q;
q = m;
m = p % q;
}
p = 2;
oriq = q = oriq / q;
while (q > 1) {
if (q % p == 0) {
ans *= p;
while (!(q % p)) q /= p;
}
p = nextpr(p);
if (p * p > oriq && oriq == q) {
ans = oriq;
break;
}
}
printf("%d\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 P, Q;
int solve() {
int b = 2;
while (1) {
int n = P;
for (int j = ((int)0); j < ((int)b); j++) {
int s = n * b / Q;
n = n * b - Q * s;
}
if (n == 0) break;
b++;
}
return b;
}
int main(void) {
cin >> 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 gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long int p, q;
cin >> p >> q;
q /= gcd(p, q);
for (long long int i = 2;; i++) {
long long int x = i;
while (x <= q) {
if (x == q) {
cout << i << endl;
return 0;
}
x *= i;
}
}
cout << q << endl;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int euclid(int x, int y) {
int t;
while (x % y) {
x %= y;
t = x;
x = y;
y = t;
}
return y;
}
int main() {
int p, q, n, m, t = 2, ans = 1;
cin >> p >> q;
n = q / euclid(p, q);
m = n;
map<int, int> f;
while (n > 1 && t < sqrt(m) + 1) {
if (!(n % t)) {
n /= t;
f[t] = 1;
}
while (!(n % t)) {
++f[t];
n /= t;
}
++t;
}
if (n != 1) f[n] = 1;
for (auto itr = f.begin(); itr != f.end(); ++itr) {
ans *= itr->first;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int COU(int a, int b) {
if (a == b || a == 0) return 1;
while (true) {
if (a == b) return a;
if (a < b) {
int t = a;
a = b, b = t;
}
a -= b;
}
}
int main() {
int p, q;
cin >> p >> q;
cout << q / COU(p, q) << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
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 << p << " " << q << endl;
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;
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);
}
int main() {
cin >> p >> q;
long long g = gcd(p, q);
p /= g;
q /= g;
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;
long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long p, q;
cin >> p >> q;
long tmp = gcd(q, p);
p /= tmp;
q /= tmp;
long ans = 1;
long root = sqrt(q) + 1;
vector<bool> hurui(q + 1, true);
for (int i = 2; i <= q / 2; i++) {
if (hurui[i] == true) {
if (i <= root) {
for (int j = 2 * i; j <= q / 2; j += i) {
hurui[j] = false;
}
}
if (q % i == 0) ans *= i;
}
}
if (ans == 1) ans = q;
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
import java.util.ArrayList;
public class Main {
Scanner sc = new Scanner(System.in);
public void run(){
int p = sc.nextInt();
int q = sc.nextInt();
calc((long)p, (long)q);
}
public void calc(long p, long q){
long a = q;
long b = p;
long max = 0;
while(true){
long c = a % b;
if(c == 0){
max = b;
break;
}
else{
a = b;
b = c;
}
}
p = p / max;
q = q / max;
long ans = -1;
for(int i = 2; i < q+1; i++){
if(q%i == 0){
long p1 = p;
long q1 = q;
long count = 0;
while(q1%i == 0){
count++;
q1 = q1/i;
}
long x = q1;
if(x < i && i%x == 0){
long y = 1;
if(x != 1) {
y = i/x;
count++;
}
p1 = p1*y;
for(int j = 0; j < count; j++){
p1 = p1 - (p1%i);
p1 = p1 / i;
}
if(p1 == 0){
ans = i;
}
}
}
if(ans != -1){
break;
}
}
System.out.println(ans);
}
public static void main(String[] args){
new Main().run();
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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];
if (now > p || now > q) break;
while (p % now == 0 && q % now == 0) p /= now, q /= now;
}
cout << q << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | import java.util.Scanner;
import java.util.ArrayList;
public class Main {
Scanner sc = new Scanner(System.in);
public void run(){
int p = sc.nextInt();
int q = sc.nextInt();
calc(p, q);
}
public void calc(int p, int q){
int a = q;
int b = p;
int ans = 0;
while(true){
int c = a % b;
if(c == 0){
ans = b;
break;
}
else{
a = b;
b = c;
}
}
q = q / ans;
System.out.println(q);
}
public static void main(String[] args){
new Main().run();
}
} |
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | 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 << 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, use;
int so[40000] = {0};
cin >> p >> q;
use = q;
int a;
while (q % p != 0) {
a = q % p;
q = p;
p = a;
}
use /= p;
q = use;
vector<int> sonaka;
for (int i = 2; i < 20000; i++)
if (so[i] == 0) {
sonaka.push_back(i);
for (int j = i * 2; j < 40000; j += i) so[j] = 1;
}
int result = 1;
for (int i = 0; sonaka[i] <= use && i < sonaka.size(); i++) {
if (use % sonaka[i] == 0) {
result *= sonaka[i];
while (use % sonaka[i] == 0) use /= sonaka[i];
}
}
cout << result * use << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
int p, q;
cin >> p >> q;
q = q / gcd(p, q);
vector<int> v;
for (int i = 2; i <= q; i++) {
if (q % i == 0) {
v.push_back(i);
while (q % i == 0) q /= i;
}
}
int r = 1;
for (int i = 0; i < v.size(); i++) r *= v[i];
cout << r << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <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];
while (q % now == 0 && p % now == 0) q /= now, p /= now;
}
int ans = 1, qq = q;
for (int i = 0; i < primes.size(); i++) {
int now = primes[i];
if (q % now == 0) ans *= now;
while (q % now == 0) q /= now;
if (now > sqrt(qq)) break;
}
cout << ans << endl;
return 0;
}
|
p01809 Let's Solve Geometric Problems | Let's solve the geometric problem
Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems.
Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in decimal is an infinite decimal number of 0.00011001100110011 ... in binary, but an error occurs when rounding this to a finite number of digits.
Positive integers p and q are given in decimal notation. Find the b-ary system (b is an integer greater than or equal to 2) so that the rational number p / q can be expressed as a decimal number with a finite number of digits. If there are more than one, output the smallest one.
Constraints
* 0 <p <q <10 ^ 9
Input Format
Input is given from standard input in the following format.
p q
Output Format
Print the answer in one line.
Sample Input 1
1 2
Sample Output 1
2
1/2 is binary 0.1
Sample Input 2
21 30
Sample Output 2
Ten
21/30 is 0.7 in decimal
Example
Input
1 2
Output
2 | {
"input": [
"1 2"
],
"output": [
"2"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int yaku(int n, int m) {
if (n % m == 0) {
return m;
}
return yaku(m, n % m);
}
int main() {
int n, m;
cin >> n >> m;
m /= yaku(n, m);
int ans = 1;
for (int i = 2; i <= m; i++) {
if (m % i == 0) {
ans *= i;
while (m % i == 0) {
m /= i;
}
}
}
cout << ans << endl;
return 0;
}
|
Subsets and Splits