文章
119
粉丝
68
获赞
92
访问
20.0k
#include <bits/stdc++.h>
using namespace std;
int stringToInt(string s){
int ans=0;
for(auto x:s){
if(isdigit(x)){
ans*=10;
ans+=x-'0';
}
}
return ans;
}
int getMaxPrime(int x){
int ans=2;
for(int i=2;i*i<=x;i++){
while(x%i==0){
ans=i;
x/=i;
}
}
if(x!=1)ans=x;
return ans;
}
int main(){
int n;
while(cin>>n){
while(n--){
string s;cin>>s;
int x=stringToInt(s);
if(x==0)cout<<"0"<<endl;
else {
cout<<getMaxPrime(x)<<endl;
}
}
}
}
登录后发布评论
暂无评论,来抢沙发