UVa 10392 Factoring Large Numbers: element factorization

Source: Internet
Author: User
Tags printf time limit

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.