10879
就是因式分解,求出两种不同的分解方案即可。
//============================================================================ // Name : 10879.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <cstdio> #include <cstring> using namespace std; bool flag[10000010]; int com[1000000]; int num, N, K, count; int main() { freopen("a.txt", "r", stdin); flag[1] = true; for(int i = 2;i <= 10000000/2;i++){ if(flag[i] == false){ for(int j = i<<1;j <= 10000000;j+=i){ flag[j] = true; } } } num = 0; for(int i = 1;i <= 10000000;i++){ if(flag[i] == false){ com[++num] = i; } } while(scanf("%d", &N)!=EOF){ for(int T = 1;T <= N;T++){ printf("Case #%d: ", T); scanf("%d", &K); printf("%d = ", K); count = 0; for(int i = 1;i <= num;i++){ if(K%com[i] == 0){ if(count == 0){ printf("%d * %d = ", com[i], K/com[i]); count++; } else if(count == 1){ printf("%d * %d\n", com[i], K/com[i]); break; } if(K%(com[i]*com[i]) == 0&&count == 1){ printf("%d * %d\n", com[i]*com[i], K/com[i]/com[i]); break; } } } } } return 0; }