#include <bits/stdc++.h> using namespace std; bool isPrime(int n){ for(int i =2;i<=sqrt(n);i++) if(n%i == 0)return false; return true; } int f(string s){ int n = stoi(s); if(isPrime(n))return n; for(int i =2;i<=sqrt(n);i++){ //分解质因数 while(n%i == 0){ n/=i; } } return n; } int main() { string s;int n;cin>>n; while(n--){ cin>>s; for(auto it = s.begin();it!=s.end();){ if(*it<'0' || *it>'9')it = s.erase(it); else it++; } if(s.length()!=0 && stoi(s)!=0)cout<<f(s)<<endl; else cout<<0<<endl; } }
有点难度