UVa 10879 Code Refactoring: Factorization

Source: Internet
Author: User
Tags printf time limit

10879-code Refactoring

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_ problem&problem=1820

"Harry, my dream are a code waiting to be broken. Break the code, solve the crime. Agent Cooper

Several algorithms in modern cryptography are based on the fact of that factoring large-is numbers. Alicia and Bobby know this, so they have decided to-design their own encryption scheme based on factoring. Their algorithm depends on a secret code, K, which Alicia sends to Bobby before sending the him. After listening carefully to Alicia's description, Yvette says, "But if I can intercept K and factor it into two positive Integers, A and B, I would break your encryption scheme! And the K values you have are at most 10,000,000. Hey, this are so easy; I can even factor it twice into two different pairs of integers! "

Input the ' a ' of input gives the number of cases, N (at most 25000). N test Cases follow. Each one contains the "code, K, on a" by itself.

Output for each test case, output one line containing "case #x: K = A * B = C * d", where A, B, C and D are different posi tive integers larger than 1. A solution would always exist.

3
210
10000000

Water.

Complete code:

/*0.038s*/
    
#include <cstdio>  
#include <cmath>  
    
int main ()  
{  
    int n, K, CNT, I, J;  
    scanf ("%d", &n);  
    for (j = 1; j <= N; ++j)  
    {  
        scanf ("%d", &k);  
        printf ("Case #%d:%d", J, K);  
        CNT = 0;  
        for (i = 2;; ++i)  
        {  
            if (k% i = = 0)  
            {  
                printf ("=%d *%d", I, k/i);  
                if (++cnt = = 2) break  
            ;  
        }  
        Putchar (' \ 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.