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:Show My code~~~~~~~0MS!!!!

Posted by 3011216073 at 2013-09-12 20:24:28 on Problem 1730
In Reply To:Show My code~~~~~~~0MS!!!! Posted by:langx at 2010-09-27 22:09:38
> Sample Input
> -2147483648
> -2147483647
> -64 
> -8
> 17
> 25
> 72
> 1073741824
> 2147483646
> 2147483647
> 
> Sample Output
> 31
> 1
> 3
> 3
> 1
> 2
> 1
> 30
> 1
> 1
> 
> 
> #include <iostream>
> #include <cmath>
> #include <map>
> using namespace std;
> 
> int n,p,i,cnt;
> map<int,int> set;
> map<int,int> ::iterator it;
> 
> bool isprime(int x)
> {
> 	if( x == 1)
> 		return false;
> 	int i,qrt = (int) sqrt(x*1.0) + 1;
> 	for ( i = 2; i < qrt; ++i ) 
> 		if( x % i == 0)
> 			break;
> 	if( i == qrt)
> 		return true;
> 	return false;
> }
> 
> void cut(int x)
> {
> 	if( x == 1){
> 		return;
> 	}
> 	if ( isprime( x ) ) {
> 		set[x]++;
> 		return;
> 	}
> 	int k,qrt = (int) sqrt(x*1.0) + 1;                       
> 	for ( k = 2; k < qrt; ++k){
> 		if( x % k == 0){
> 			if ( isprime( k ) ) {
> 				set[k]++;
> 				cut(x/k);
> 				break;
> 			}
> 		}
> 	}
> } 
> 
> int main()
> {
> 
> 	while ( ~scanf("%ld",&n) && n ) {
> 		if( n == -2147483648 )
> 			p = 31;
> 		else{
> 			cut( abs( n ) );
> 			p = 1;
> 			if( set.size() != 0 ) {
> 				for ( it = set.begin(); it != set.end(); ++it ) {
> 					if(it == set.begin())
> 						cnt = (*it).second;
> 					else if((*it).second < cnt ) 
> 						cnt = (*it).second;
> 				} 
> 				for ( i = cnt; i > 0; --i) {
> 					for ( it = set.begin(); it != set.end(); ++it )
> 						if((*it).second % i != 0 )
> 							break;
> 					if(it == set.end()){
> 						p = i;
> 						break;
> 					}
> 				}
> 				if( n < 0)
> 					while ( p % 2 == 0) 
> 						p /= 2;		
> 			}
> 			set.clear();
> 		}
> 		printf("%d\n",p);
> 	}
> 	system("pause");
> 	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