UVa 10879: Code Refactoring

来源:互联网 发布:内蒙古艺术学院网络 编辑:程序博客网 时间:2024/04/29 15:28

这题只要用两种方式分解一个不超过10,000,000的数就可以了。很简单就能过了。


我的解题代码:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>using namespace std;int main(){int N;int K;cin >> N;for(int k=0; k<N; k++){cin >> K;cout << "Case #" << k+1 << ": " << K << " = ";int times=0;for(int i=2; i*i<=K; i++) if(times<2){if(K%i==0) {if(times==0){cout << i << " * " << K/i << " = ";times++;}else if(times==1){cout << i << " * " << K/i << endl;times++;}}}else break;}return 0;}


原创粉丝点击