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 litchiwin at 2007-06-05 12:12:40 on Problem 2992
#include <stdio.h>
#include <memory.h>

int prime[]={2,3,5,7,11,13,17,19,23};

void fun(int n,int *a){
	int i;
	for(i=0;i<9;i++)
		while(n%prime[i]==0){
			n/=prime[i];
			a[prime[i]]++;
		}
	if(n!=1) a[n]++;
}

int main(){
	int a[432],b[432];
	int i,n,k;
	_int64 s;
	while(scanf("%d %d",&n,&k)!=EOF){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		s=1;
		for(i=n;i>=n-k+1;i--)
			fun(i,a);
		for(i=2;i<=k;i++)
			fun(i,b);
		for(i=2;i<=n;i++)
			a[i]-=b[i];
		for(i=2;i<=n;i++)
			if(a[i]!=0) s*=a[i]+1;
		printf("%I64d\n",s);
	}
	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