-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbig.cpp
84 lines (82 loc) · 1.27 KB
/
big.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<bits/stdc++.h>
using namespace std;
typedef long long li;
string multiply(string s1,string s2)
{
int i,j,tmp;
int l1=s1.size();
int l2=s2.size();
int ans[l1+l2+1]={0},a[l1+l2+1],b[l1+l2+1];
string ret="";
for(i = l1-1,j=0;i>=0;i--,j++)
{
a[j] = s1[i]-'0';
}
for(i = l2-1,j=0;i>=0;i--,j++)
{
b[j] = s2[i]-'0';
}
for(i = 0;i < l2;i++)
{
for(j = 0;j < l1;j++)
{
ans[i+j] += b[i]*a[j];
}
}
for(i = 0;i < l1+l2;i++)
{
tmp = ans[i]/10;
ans[i] = ans[i]%10;
ans[i+1] = ans[i+1] + tmp;
}
for(i = l1+l2; i>= 0;i--)
{
if(ans[i] > 0)
break;
}
for(;i >= 0;i--)
{
//printf("%d",ans[i]);
ret+=(ans[i]+'0');
}
return ret;
}
int main()
{
li t;
string a,b;
//cout<<multiply("4096","4")<<endl;
cin>>t;
for(int k=1;k<=t;k++)
{
string ans="1";
cin>>a>>b;
for(int i=1;;i++)
{
ans=multiply(ans,a);
bool flag=true;
if(ans.size()>=b.size())
{
for(int is=0;is<b.size();is++)
{
if(ans[is]!=b[is])
{
flag=false;
break;
}
}
}
else
{
flag=false;
}
if(flag)
{
//cout<<ans<<endl;
printf("Case %d: %d\n",k,i);
break;
}
}
}
return 0;
}