Hints: long long int can not contain such a big type of data as there may be 10^6 digit. string or char data type can contain but you will get time limit exceed as you need to process loop 10^6*10^6=10^12 times. so simply check divisibility digit by digit such as if input is 3 1 then number is=111 . so at first check 1 then 11 and last 111. that remainder r can be checked by this rule (if n is 3 and m is 1) r=(r*10+m)%n
#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("id.txt","r",stdin);
//freopen("idout.txt","w",stdout);
long long int i,j,n,t,l,z,m,k,r;
string s;
cin>>t;
for(i=1;i<=t;i++)
{
cin>>n>>m;
r=0;
l=0;
for(j=0;j<n;j++)
{
r=(r*10+m)%n;
l++;
if(r==0)
{
break;
}
}
printf("Case %lld: %lld\n",i,l);
}
return 0;
}
0 comments:
Post a Comment