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

Re:推导过程及代码

Posted by NENU08022 at 2010-06-05 08:58:11 on Problem 2917
In Reply To:推导过程及代码 Posted by:dinysirius at 2009-10-05 10:14:54
这么改可以免去独判n==1的情况

> int solve(int n) {
> 	int ans = 1,t;
> 	for(int i = 0 ; prime[i]*prime[i] <= n && i < tot ; i ++ ) {
> 		t = 0;
> 		while(!(n % prime[i])) {
> 			t ++;
> 			n /= prime[i];
> 		}
> 		ans *= 2*t+1;
> 	}
> 	if(ans == 1 || n != 1)//这里可以只判n!=1即可,这样就可以免除独判n==1的情况;
> 		ans *= 3;
> 	return ans;
> }
> 
> int main() {
> 	int t,n,var=0;
> 	scanf("%d",&t);
> 	init();
> 	while(t -- ) {
> 		scanf("%d",&n);
> 		int ans = solve(n);
> 		printf("Scenario #%d:\n",++var);
> 		//if(n == 1) ans = 1;
> 		printf("%d\n\n",(ans+1)/2);
> 	}
> 	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