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

那位大侠帮我看看,为什么总是WA阿,我硬算的等比数列和,即使不过也应该是超时阿???

Posted by on_pku at 2011-07-23 23:07:30 on Problem 1845
//why Wrong Answer??????????????????????????????
#include <stdio.h>
#include <math.h>

#define M 9901

int main()
{
	long long int A,B;
	long long  i,j,k,temp,ans,expo;
	long long  p[30],c[30];
	scanf("%lld %lld",&A,&B);
	int root_A = (int)sqrt((double)A);
	k = 0;
	temp = A;
	for(i = 2; i <= root_A; i++){//find n's prime factors and order of each factor
		if(temp % i == 0){
			p[k] = i;
			temp = temp/i;
			c[k] = 1;
			while(temp % i == 0){
				temp = temp/i;
				c[k]++;
			}
			k++;
		}
	}
	if(temp > 1){//if temp eventually doesn't decreased to 1, then temp must itself be a prime factor
		p[k] = temp;
		c[k++] = 1;
	}
	ans = 1;
	for(i = 0; i < k; i++){//for each prime factor
		temp = 1 + p[i];
		expo = p[i];
		for(j = 2; j <= c[i]*B; j++){
			expo = expo*p[i] % M;
			temp = (temp + expo) % M;
		}
		ans = (ans*temp) % M;
	}
	printf("%lld\n",ans);
	
	return 0;
}

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