我的代码:
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
const int k=2000001;
int n;
bool b[k];
long long zhi[k],x_z;
void shai(){
b[1]=1;
for(int i=2;i<=k;i++){
if(!b[i])zhi[++x_z]=i;
for(int j=1;j<=x_z&&i*zhi[j]<=k;j++){
b[i*zhi[j]]=1;
if(!(i%zhi[j]))break;
}
}
}
long long x;
int main(){
//freopen("rd.txt","r",stdin);
//freopen("try.txt","w",stdout);
cin>>n;
shai();
for(int i=1;i<=n;i++){
cin>>x;
for(int j=1;j<=x_z;j++){
if(x==1)break;
while(!(x%zhi[j])){
cout<<zhi[j]<<' ';
x/=zhi[j];
}
}
cout<<endl;
}
return 0;
}
对拍:
#include<iostream>
#include<cstdio>
#include<windows.h>
using namespace std;
int main(){
while(1){
//分别运行代码对应可执行文件
system("rd.exe");
system("try.exe");
system("ans.exe");
if(system("fc try.txt ans.txt"))break;//比对输出
}
return 0;
}
标程:
#include <iostream>
int main() {
//freopen("rd.txt","r",stdin);
//freopen("ans.txt","w",stdout);
int T;
for (std::cin >> T; T; --T) {
long long n; std::cin >> n;
long long m = n;
for (int i = 2; 1ll * i * i <= n; ++i) while (m % i == 0) {
m /= i;
std::cout << i << ' ';
}
if (m != 1) {
std::cout << m;
}
std::cout << std::endl;
}
return 0;
}
不知道为何不同,肉眼难以分辨