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

AC了,呵呵

Posted by Caiboss at 2007-07-09 22:35:53 on Problem 1365
In Reply To:HELP!!!过了的帮忙看看,为什么WA啊! Posted by:Caiboss at 2007-07-09 21:54:48
> #include <iostream>
> #include <math.h>
> using namespace std;
> int Prime[17000];
> int ans[32800];
> int main() {
> 	int k = 0;
> 	Prime[k++] = 2;
> 	for(int i = 3;i<=33000; i+=2) {
> 		int j,M = (int)sqrt(i)+1;
> 		for(j = 2; j< M; ++j)	if(i%j == 0)	break;
> 		if(j == M)	Prime[k++] = i;	
> 	}
> 	char p[81];
> 	while(cin.getline(p,80)) {
> 		if(p[0] == '0')	break;
> 		int L = strlen(p);
> 		long long s = 0;
> 		long long sum = 1;
> 		for(int i = 0; i< L; ++i) {
> 			if(p[i] == ' ')	{
> 				sum *= s;
> 				s = 0;
> 				continue;
> 			}
> 			s = s*10+p[i]-'0';
> 		}
> 		sum --;
> 		int j = 0;
> 		for(int i = 0; i< 32800; ++i)	ans[i] = 0;
> 		while(sum>1) {
> 			while(sum%Prime[j])	j++;
> 			ans[Prime[j]]++;
> 			sum/=Prime[j];
> 		}
> 		for(int i = 32800; i>=0; --i)	if(ans[i])	cout << i << ' ' << ans[i] << ' ';
> 		cout << endl;
> 	}
> 	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