HDU 1164 Eddy's research I
题意:把一个数拆成素数,从小到大排列。如果把素数全部存起来大概快一半的样子
#include<stdio.h> #include<string.h> #define Max 65540 int n,prime[Max+5],num[Max],c = 0; void DFS( int x ) { if( x == 0 ) return ; for( int i = 0; i < c; ++i ) { if( x % num[i] == 0 ) { printf( x == n?"%d":"*%d",num[i] ); DFS( x / num[i] ); break; } } } int main( ) { memset( prime,0,sizeof( prime ) ); prime[0] = prime[1] = 1; for( int i = 2; i <= Max / 2; ++i ) if( !prime[i] ) for( int j = i + i; j <= Max; j += i ) prime[j] = 1; for( int i = 2; i <= Max; ++i ) if( !prime[i] ) num[c++] = i; while( scanf( "%d",&n ) != EOF ) DFS( n ),puts( "" ); return 0; }
本人还是新手 ,转载请注明来自Lvsi‘s home