历年上机题------大整数的因子

思路:模拟大数取模运算即可

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
bool check(string s,int k)
{
    int remind=0;
    int res=0;
    for(int i=0;i<s.size();i++)
    {
        res = (remind*10 +s[i]-'0');
        remind = res%k;
    }
    return remind==0;
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    string s;
    while(cin>>s)
    {
        if(s=="-1") break;
        vector<int> ans;
        for(int i=2;i<=9;i++)
        {
            if(check(s,i))
            {
                ans.push_back(i);
            }
        }
        if(ans.size()==0)
        {
            cout<<"none"<<endl;
            continue;
        }
        for(int i=0;i<ans.size()-1;i++)
        {
            cout<<ans[i]<<" ";
        }
        cout<<ans[ans.size()-1]<<endl;
    }
    return 0;
}
发布了449 篇原创文章 · 获赞 197 · 访问量 25万+

猜你喜欢

转载自blog.csdn.net/qq_40774175/article/details/105405149