| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:谁能给组测试数据In Reply To:谁能给组测试数据 Posted by:wavemoon at 2005-08-04 20:11:49 > 能不能给点数据。。
> 有没有什么要注意的地方
#include<stdio.h>
#include<math.h>
struct sss{
int e;
int d;
};
struct sss sa[1000000];
int a,b,sai;
int m,n;
int modx,mody;
void fenjie()//分解质因数。。。
{
int i,j,k,tp;
sai=0;
k=0;tp=a;
if(a%2==0)
{
while(a%2==0)
{
k++;
a/=2;
}
sa[sai].e=k; // 指数
sa[sai++].d=2;//底数
}
for(i=3;;i+=2)
{
if(a%i==0)
{
k=0;
while(a%i==0)
{
k++;
a/=i;
}
sa[sai].e=k;
sa[sai++].d=i;
}
if(a==1) break;
}
a=tp;
}
void mod(int tpa,int tpb)
{
if(tpb==0)
{
modx=1;mody=0;
return;
}
mod(tpb,tpa%tpb);
int tp=modx;
modx=mody;
mody=tp-(tpa/tpb)*mody;
}
int modan(int tpa,int tpb)
{
int d=1,t=tpa;
while(tpb>0)
{
if(tpb&1) d=(d*t)%9901;
t=(t*t)%9901;
tpb>>=1;
}
return d;
}
int outp()
{
int i,j,k;
int tp,tpp=1;
for(i=0;i<sai;i++)
{
tp=modan(sa[i].d,sa[i].e*b+1);
tp=(tp-1+9901)%9901;
mod(sa[i].d-1,9901);
while(modx<0) modx+=9901;
tp=((modx%9901)*tp)%9901;
tpp=tpp*tp;
tpp=tpp%9901;
}
return tpp;
}
main()
{
int i,j;
int tp;
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a==0) { printf("0\n");continue;}
if(b==0) { printf("1\n");continue;}
fenjie();
j=outp();
printf("%d\n",j);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator