Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:推导过程及代码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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator