原题链接:点我转移
#include<bits/stdc++.h> using namespace std; int main() { char c[31]; while(cin>>c) { int len = strlen(c), flag = 0; for(int i = 2; i <= 9; i++) { int yushu = 0; for(int j = 0; j < len; j++)///对于这里建议列竖式进行计算,就能看出余数的秘密(>^ω^<)喵 { yushu = (yushu * 10 + (c[j] - '0')) % i; } if(yushu == 0)///看最后的余数是不是0是0就说明能整除 { flag = 1; cout << i << " "; } } if(flag == 0) cout << "none"; cout<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { char c[31]; while(cin>>c) { int len = strlen(c), flag = 0; for(int i = 2; i <= 9; i++) { int yushu = 0; for(int j = 0; j < len; j++)///对于这里建议列竖式进行计算,就能看出余数的秘密(>^ω^<)喵 { yushu = (yushu * 10 + (c[j] - '0')) % i; } if(yushu == 0)///看最后的余数是不是0是0就说明能整除 { flag = 1; cout << i << " "; } } if(flag == 0) cout << "none"; cout<<endl; } return 0; }