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 570668687 at 2007-06-21 17:06:08 on Problem 2992
这题还要怎么优化?
#include<stdio.h>
#include<string.h>

#define N 500

int prime[N/4] = {1,2,3,5,7,0};
int pres[N];

void make_prime()
{
	int p, i, np = 4;
	bool flag;
	for(p = 7; p < N; p += 2)
	{
		flag = true;
		for(i = 2; prime[i] < p; i++)
		{
			if(!prime[i])
				break;
			if(p % prime[i] == 0)
			{
				flag = false;
				break;
			}
		}
		if(flag)
		{
			np++;
			prime[np] = p;
		}
	}
}

void make_pres(int n, int k)
{
	int i, j, t;
	for(i = n; i >(n - k); i--)
	{
		j = 0;
		t = i;
		while(t!=1)
		{
			j++;
			while(t%prime[j] == 0)
			{
				pres[j]++;
				t /= prime[j];
			}
		}
	}
	for(i = 2; i <= k; i++)
	{
		j = 0;
		t = i;
		while(t != 1)
		{
			j++;
			while(t%prime[j] == 0)
			{
				pres[j]--;
				t /= prime[j];
			}
		}
	}
}

int main()
{
	int i, n, k;
	__int64 sum;
	make_prime();
	while(scanf("%d%d",&n,&k) != EOF)
	{
		memset(pres,0,sizeof(pres));
		make_pres(n,k);
		sum = 1;
		for(i = 1; i <= n; i++)
		{
			if(pres[i])
				sum *= (pres[i] + 1);
		}
		printf("%I64d\n",sum);
	}
	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