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/