【SGU】113. Nearly prime numbers 合数分解
2014-11-06 11:29
357 查看
传送门:【SGU】113. Nearly prime numbers
题目分析:O(sqrt(N))。。
代码如下:
题目分析:O(sqrt(N))。。
代码如下:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std ; #define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i ) #define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i ) #define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i ) #define clr( a , x ) memset ( a , x , sizeof a ) const int MAXN = 5 ; int n ; bool check ( int x ) { int top = 0 ; for ( int i = 2 ; i * i <= x ; ++ i ) { if ( x % i == 0 ) { while ( x % i == 0 ) { x /= i ; top ++ ; if ( top > 2 ) return 0 ; } } } if ( x > 1 ) ++ top ; return top == 2 ; } void solve () { int x ; For ( i , 1 , n ) { scanf ( "%d" , &x ) ; printf ( check ( x ) ? "Yes\n" : "No\n" ) ; } } int main () { while ( ~scanf ( "%d" , &n ) ) solve () ; return 0 ; }
相关文章推荐
- [SGU]113. Nearly prime numbers
- SGU 113 Nearly prime numbers
- sgu 113 Nearly prime numbers
- sgu 113 Nearly prime numbers
- sgu 113 Nearly prime numbers
- SGU113—— Nearly prime numbers
- 113. Nearly prime numbers
- 113. Nearly prime numbers
- SGU 113 Nearly prime numbers
- SGU 113 Nearly prime numbers(素数判定)
- SGU 113 Nearly prime numbers
- SGU 113 Nearly prime numbers
- Nearly prime numbers - SGU 113(素数)
- (Relax 数论 1.5)POJ 1811 Prime Test(MillRabin模板题+Pollard模板题:判定大素数&&合数分解)
- 一个数是否由两个质数组成——SGU113 Nearly prime numbers
- sgu113:Nearly prime numbers
- [数论] HOJ 1015 Nearly prime numbers 筛素数
- POJ 1811 Prime Test(大素数判断+大合数素因子分解)
- hoj 1015 Nearly prime numbers
- SGU113 Nearly prime numbers