10392-factoring Large Numbers
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_ problem&problem=1333
One of the the ideas behind much cryptography was that factoring large numbers is computationally intensive. In this context one might use a digit number, which is a product of two digit prime numbers. Even with the fastest projected computers this factorization would take hundreds of years.
You don ' t have those computers available, but if your are clever you can still factor fairly to large.
Input
The input would be a sequence of the integer values, one on line, and terminated by a negative number. The numbers would fit in GCC ' s long int datatype. You could assume that there'll be in most one factor more than 1000000.
Output
Each positive number from the input must is factored and all factors (other than 1) is printed out. The factors must is printed in ascending order with 4 leading spaces preceding a left justified number, and followed by a Single blank line.
Sample Input
90
1234567891
18991325453139
12745267386521023
-1
Sample Output
2
3
3
5
1234567891
3
3
13
179
271
1381
2423
30971
411522630413
Water.
Complete code:
/*0.016s*/#include <cstdio> #include <cstring> #include <cmath> typedef long LL;
const int MAXN = 100000;
LL PRIME[MAXN], C;
BOOL VIS[MAXN];
inline void Make_prime () {LL I, J;
for (i = 2; i < MAXN i++) if (!vis[i]) {prime[c++] = i;
for (j = i * i; j < maxn; J + = i) vis[j] = true;
int main () {LL n, I, X;
Make_prime ();
while (scanf ("%lld", &n), ~n) {x = sqrt (n);
for (i = 0; Prime[i] <= x && i < C;)
{if (n% prime[i] = = 0) {printf ("%lld\n", Prime[i]);
n/= Prime[i];
if (n = = 1) break;
else ++i; } if (n!= 1) printf ("%lld\n", N);///there'll be on most one factor more than 1000000 (' \
n '); return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/