uva 10879 – Code Refactoring

來源:互聯網
上載者:User

 

Problem B
Code Refactoring
Time Limit: 2 seconds

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

Agent Cooper

Several algorithms in modern cryptography are based on the fact that factoring large numbers is difficult. 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, that Alicia sends to Bobby before sending him an encrypted message. 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 use are at most 10,000,000. Hey, this is so easy; I can even factor it twice, into two different pairs of integers!"

Input
The first line of input gives the number of cases, N (at most 25000).
N test cases follow. Each one contains the code, K, on a line 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 positive integers larger than 1. A solution will always exist.

Sample Input Sample Output
312021010000000
Case #1: 120 = 12 * 10 = 6 * 20Case #2: 210 = 7 * 30 = 70 * 3Case #3: 10000000 = 10 * 1000000 = 100 * 100000

#include<stdio.h>
void main()
{int t,i,j,n,k;
 scanf("%d",&t);
 for (k=1;k<=t;k++)
 {scanf("%d",&n);
  i=2;j=0;
  while (j<2)
  {
   if (n%i==0)
   {++j;
    if (j==1) printf("Case #%d: %d = %d * %d",k,n,i,n/i);
    if (j==2) printf(" = %d * %d\n",i,n/i);
   }
   ++i;
  }
 }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.