Uva--10392 (数学)
2014-06-12 01:11:10
题意&思路:素数拆分,注意一下中间判素数直接输出而防止超时。
#include <cstdio> #include <cmath> #include <iostream> using namespace std; bool isprime(long long x){ for(long long i = 2; i * i <= x; ++i){ if(x % i == 0) return false; } return true; } int main(){ long long num; while(scanf("%lld",&num) == 1){ if(num <0 ) break; if(isprime(num)){ printf(" %lld\n\n",num); continue; } int flag = 0; for(long long i = 2; num != 1; ++i){ while(num % i == 0){ printf(" %lld\n",i); num /= i; if(num != 1 && isprime(num)){ printf(" %lld\n",num); flag = 1; break; } } if(flag) break; } puts(""); } return 0; }