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:Show My code~~~~~~~0MS!!!!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator