Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这样的程序也会错,偶是没办法了,给个TLE还甘心

Posted by ecjtubaowp at 2006-12-23 09:35:52 on Problem 1845
//将A进行质因数分解得到p1, p2, p3....数量分别是n1, n2, n3
//A^B的所有约数的和是(p1^0 + p1^1 + ......+p1^(n1 * B)) * (p2 ^0 + p2^1 + ....p2^(n2 * B))*...
#include<stdio.h>
#include<math.h>
#define mod 9901
int prime[50000],P[50000],total[50000];
int sum;
int a[10000];
int modn(int base,int pow)
{
 int i,j;
 __int64 m0;
 m0=pow;i=0;
 while(m0)
 {a[i]=m0%2;i++;m0/=2;
 }
 m0=base;sum=1;
 for(j=0;j<i;j++)
 {
  if(a[j])sum=(sum*m0)%mod;
  
  m0=(m0*m0)%mod;
 }
 
 return sum;
 
}
int fun(int p,int n)//计算 1+p+p^2+.....+p^n 对9901求模
{
 if(n<1)return 1;
 else
 {
  if(n%2 == 1)
  return (fun(p,n/2)*(1+modn(p,n/2+1))) % mod;
  else
  return (fun(p,n-1)+modn(p,n)) % mod;
  }
}
bool isprime(int n)//判断素数 
{
 int i,m;m=sqrt(n);
 for(i=2;i<=m;i++)
 if(n%i==0)break;
 if(i>m)return 1;
 else return 0;
 }
int main()
{
 int i,j,k=0,m,n,sum0,s;
 int A,B,result;
 bool flag;
 prime[1]=2;prime[2]=3;
 k=2;
 for(i=5;i<=100000;i+=2)
 {
  for(j=1;prime[j]*prime[j]<=i;j++)
  if(i%prime[j]==0)goto loop;
  k++;prime[k]=i;
  loop:;
 }
 prime[0]=k;
 while(scanf("%d%d",&A,&B)!=EOF)
 {
 m=A;n=B;
 flag=isprime(m);
 if(flag)
 {result=fun(m,n);
 //printf("%d\n",sum);
 
 }
 else 
 {
  for(i=1;i<=prime[0];i++)
  {s=0;
   while(m%prime[i]==0)
   {s++;m/=prime[i];
   }
   if(s>0){k++;P[k]=prime[i];total[k]=s;}
   if(m==1)break;
   if(prime[i]>m/prime[i]){k++;P[k]=m;total[k]=1;break;}
  }
  result=1;
  for(i=1;i<=k;i++)
  {sum0=fun(P[i],total[i]*n);
   result=(result*sum0)%mod;
   
  }
 }
 
 printf("%d\n",result);
 }
 
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator