#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const long long MOD=1e12;
int flag;
LL k1,k2;
LL multi(LL a,LL b,LL mod){
LL l=a * (b>>20) % mod * (1LL<<20) % mod;
LL r=a * (b&((1LL<<20)-1)) %mod;
return (l+r)%mod;
}
LL qmod(LL a,LL b,LL mod){
LL res=1;
while(b){
if(b&1)
res=multi(res,a,mod);
a=multi(a,a,mod);
b>>=1;
}
return res%mod;
}
void dfs(int d,LL res,LL mod){
if(d==12){
if(res<1e11||qmod(k1,res,mod)!=res)
return ;
k2=res;
flag=1;
return ;
}
for(int i=0;i<=9;i++){
LL s=res+mod*i;
LL t1=qmod(k1,s,mod);
LL t2=s%mod;
if(t1==t2){
dfs(d+1,s,mod*10);
}
if(flag)
return ;
}
}
int main(){
int t=1;
while(~scanf("%lld",&k1)&&k1){
flag=0;
dfs(0,0,1);
printf("Case %d: Public Key = %lld Private Key = %lld\n",t++,k1,k2%MOD);
}
}
uvalive 4998 高次幂的求模 (同余)
最新推荐文章于 2021-12-15 17:36:22 发布