this is my code
I am getting run error on one test case
For which test case are you getting error? Generally when only one test case is failing it is due to some base case missing or very big test case for which the code is not optimized
2nd last test case run error
please clear my doubt
looking into it right now …if you are free we can discuss
Hi I have made some changes to your code. felt a lot of unnecessary stuff was there which I removed. It is now working fine on the second last test case.
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define sd(val) scanf("%d",&val)
#define ss(val) scanf("%s",&val)
#define sl(val) scanf("%lld",&val)
#define all(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long int
#define MOD 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// ll fastexpo(ll a,ll b,ll c)
// {
// ll res=1;
// while(b>0)
// {
// if(b&1)
// {
// res=(res*a)%c;
// }
// a=(a*a)%c;
// b=b>>1;
// }
// return res;
// }
ll gcd(ll a,ll b)
{
if (!a)
return b;
return gcd(b%a,a);
}
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ll n;string m;
cin>>n>>m;
int len=m.length();
ll num=0;
for(int i=0;i<len;i++)
{
num = (num*10 + m[i] - '0')%n;
}
ll ans=gcd(n,num);
cout<<ans;
return 0;
}
now also the same error is coming
second last test case input is 1000004 10000040000000000000000000
and output is 1000004
My answer is coming correctly for this test case (test case #3)
0 98789675643215678890987654321234567776567788893374782227464722934643728293475692292111023874
For this test case the output is coming as
/bin/run.sh: line 4: 18 Arithmetic exception (core dumped) ./exe
unsigned int bigmodulus(string bignumber, int m) {
static const int modulus_multiply_e6 = 100000 % m;
if (bignumber.length() <= 5) {
int currNumber;
stringstream(bignumber) >> currNumber;
return (currNumber % m);
}
string rightFiveDigit = bignumber.substr(bignumber.length()-5, 5);
bignumber = bignumber.substr(0, bignumber.length()-5);
int remainder;
stringstream(rightFiveDigit) >> remainder;
int modulusRemainder = remainder % m;
return (bigmodulus(bignumber, m)*modulus_multiply_e6 + modulusRemainder) % m;
}
insert this function into your code and see if it helps. This will be your main called function from main program which will then call the euclidean gcd function