UVa 10392 - Factoring Large Numbers
2014-06-19 11:12
417 查看
题目:将一个long long类型的2数字分解。
分析:数论。题目说明最多只有一个因子大于1000000,因此将1000000以内的素数打标,依次去除即可。
说明:输出格式前面有4个空格;注意余数不是1的时候,是超过1000000的余数,别忘记输出。
分析:数论。题目说明最多只有一个因子大于1000000,因此将1000000以内的素数打标,依次去除即可。
说明:输出格式前面有4个空格;注意余数不是1的时候,是超过1000000的余数,别忘记输出。
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; int used[1000000]; int prim[1000000]; int main() { memset( used, 0, sizeof(used) ); int count = 0; for ( int i = 2 ; i < 1000000 ; ++ i ) if ( !used[i] ) { prim[count ++] = i; for ( int j = i<<1 ; j < 1000000 ; j += i ) used[j] = 1; } long long n; while ( scanf("%lld",&n) && n > 0 ) { int now = 0; while ( now < count && prim[now] <= n ) { while ( n%prim[now] == 0 ) { printf(" %d\n",prim[now]); n /= prim[now]; } now ++; } if ( n > 1 ) printf(" %lld\n",n); printf("\n"); } return 0; }
相关文章推荐
- UVA - 10392 Factoring Large Numbers
- Uva 10392 Factoring Large Numbers
- UVa 10392 Factoring Large Numbers(分解因数)
- UVa 10392 - Factoring Large Numbers
- UVa 10392 Factoring Large Numbers
- uva 10392 - Factoring Large Numbers
- UVA - 10392 Factoring Large Numbers
- UVa 10392 Factoring Large Numbers
- uva10392 Factoring Large Numbers
- UVA 10392 (暑假-数论- G - Factoring Large Numbers)
- UVa 10392 - Factoring Large Numbers
- uva 10392 Factoring Large Numbers
- UVA 10392--Factoring Large Numbers
- UVa 10392: Factoring Large Numbers
- UVA - 10392 Factoring Large Numbers
- uva 10392 - Factoring Large Numbers
- UVA - 10392 Factoring Large Numbers(素数打表)
- uva-10392 - Factoring Large Numbers
- UVA 10392 - Factoring Large Numbers
- UVA 10392 Factoring Large Numbers