判断大整数能否被整除,直接用字符串从最高位开始取余即可
#include<iostream> #include<string> using namespace std; bool isDividable(string num,int divider){ int total = 0; for(int i=0;i<num.size();i++){ int digit = num[i]-'0'; total *= 10; total += digit; total %= divider; } return total==0; } int main(){ string c; while(cin>>c){ if(c=="-1") break; bool first = true; for(int i=2;i<=9;i++){ if(isDividable(c,i)){ if(first){ first = false; } else { cout<<" "; } cout<<i; } } if(first) cout<<"none"; cout<<endl; } return 0; }