1uva10879(数论)

来源:互联网 发布:什么是淘宝同步单 编辑:程序博客网 时间:2024/06/15 22:11

 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1820

10879 - Code Refactoring

Time limit: 3.000 seconds

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 factthat factoring large numbers is difficult. Alicia and Bobby knowthis, so they have decided to design their own encryption schemebased on factoring. Their algorithm depends on a secret code,K, that Alicia sends to Bobby before sending him anencrypted message. After listening carefully to Alicia'sdescription, Yvette says, "But if I can intercept K andfactor it into two positive integers, A and B, Iwould break your encryption scheme! And the K values you useare at most 10,000,000. Hey, this is so easy; I can even factor ittwice, into two different pairs of integers!"

Input
The first line of input gives the number of cases, N (atmost 25000). N test cases follow. Each one contains thecode, K, on a line by itself.

Output
For each test case, output one line containing "Case #x:K = A * B = C * D", whereA, B, C and D are different positiveintegers larger than 1. A solution will always exist.

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

Problemsetter: Igor Naverniouk

题意:把一个数拆分成不同的两组分别由两个数相乘。

简单题:1Y。

思路:直接枚举就是了。。

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn =10;
int a[maxn];
int main()
{
 int n;
 scanf("%d",&n);
 int cases=1;
 while(n--)
 {
  int k;
  scanf("%d",&k);
  int i,count=0;
  for(i=2;i<=k;i++)
  {
   if(k%i==0)
   {
    a[count++]=i;
    a[count++]=k/i;
   }
   if(count==4)
    break;
  }
  printf("Case #%d: %d = %d * %d= %d * %d\n",cases++,k,a[0],a[1],a[2],a[3]);
 }
 return 0;
}

原创粉丝点击