题解 | #Problem C#
Problem C
https://www.nowcoder.com/practice/2a05dcaa4cde4db989443f206ee3e5c5
#include <iostream> using namespace std; string s; int get_p(int x){ int res = 0; for(int i = 2; i <= x / i; i ++){ if(x % i == 0){ while(x % i == 0){ x /= i; res = max(res, i); } } } if(x) res = max(x, res); return res; } int main(){ int m; cin>>m; while(m--){ cin>>s; bool flag = false; int num = 0; for(int i = 0; i < s.size(); i ++){ if(isdigit(s[i])){ num = num * 10 + s[i] - '0'; if(num != 0) flag = true; } } if(flag) cout<<get_p(num)<<endl; else cout<<0<<endl; } return 0; }