- Joined
- Nov 28, 2024
- Messages
- 1
- Reaction score
- 0
i don't know why my code to check if and integer make of a1*a2*... an divided for b1*b2...*bn is a repeating or finite but there is RE?
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
#define pb push_back
#define EL cout<<endl;
#define fill(a,x) memset(a,x,sizeof(a))
#define pll pair<ll,ll>
const ll M = 1e9+7;
const ll MaxN = 1e5+5;
vll a,b;
bool kt(ll n)
{
if(n<1) return false;
if(n%2 != 0 && n%5 != 0) return false;
while(n%2==0 && n>1)
n /= 2;
while(n%5==0 && n>1)
n /= 5;
if(n>1) return false;
return true;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll t,n,x;
cin>>t;
while(t--)
{
cin>>n;
a.clear();
b.clear();
ll X=1, Y=1;
for(ll i=0; i<n; i++)
{
cin>>x;
a.pb(x);
}
for(ll i=0; i<n; i++)
{
cin>>x;
b.pb(x);
}
for(ll i=0; i<n; i++)
{
if(a!=0 && b!=0)
{
ll tmp1 = __gcd(a,b);
if(tmp1 != 0)
{
a = a/tmp1;
b = b/tmp1;
}
}
X = X*a;
Y = Y*b;
if(X!=0 && Y!=0)
{
ll tmp2 = __gcd(X,Y);
if(tmp2 != 0)
{
X /= tmp2;
Y /= tmp2;
}
}
}
if(X%Y==0 || X==0)
cout<<"finite" <<endl;
else
{
if(kt(Y)==true) cout<<"finite" <<endl;
else cout<<"repeating" <<endl;
}
}
}
//4
//2 1 7 5 6
//1 3 20
//1 4 1
//1 116 495
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
#define pb push_back
#define EL cout<<endl;
#define fill(a,x) memset(a,x,sizeof(a))
#define pll pair<ll,ll>
const ll M = 1e9+7;
const ll MaxN = 1e5+5;
vll a,b;
bool kt(ll n)
{
if(n<1) return false;
if(n%2 != 0 && n%5 != 0) return false;
while(n%2==0 && n>1)
n /= 2;
while(n%5==0 && n>1)
n /= 5;
if(n>1) return false;
return true;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll t,n,x;
cin>>t;
while(t--)
{
cin>>n;
a.clear();
b.clear();
ll X=1, Y=1;
for(ll i=0; i<n; i++)
{
cin>>x;
a.pb(x);
}
for(ll i=0; i<n; i++)
{
cin>>x;
b.pb(x);
}
for(ll i=0; i<n; i++)
{
if(a!=0 && b!=0)
{
ll tmp1 = __gcd(a,b);
if(tmp1 != 0)
{
a = a/tmp1;
b = b/tmp1;
}
}
X = X*a;
Y = Y*b;
if(X!=0 && Y!=0)
{
ll tmp2 = __gcd(X,Y);
if(tmp2 != 0)
{
X /= tmp2;
Y /= tmp2;
}
}
}
if(X%Y==0 || X==0)
cout<<"finite" <<endl;
else
{
if(kt(Y)==true) cout<<"finite" <<endl;
else cout<<"repeating" <<endl;
}
}
}
//4
//2 1 7 5 6
//1 3 20
//1 4 1
//1 116 495