13:大整数的因子

13:大整数的因子

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k。

输入
一个非负整数c,c的位数<=30。
输出
若存在满足 c%k == 0 的k,从小到大输出所有这样的k,相邻两个数之间用单个空格隔开;若没有这样的k,则输出"none"。
样例输入
30
样例输出
2 3 5 6 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 char a1[10001];
 6 int a[10001];
 7 int c[10001];
 8 int tot;
 9 int main()
10 {
11     gets(a1);
12     int la=strlen(a1);
13     for(int i=0;i<la;i++)
14     {
15         a[i+1]=a1[i]-48;
16     }
17     int x=0;//
18     for(int j=2;j<=9;j++)
19     {
20         memset(c,0,sizeof(c));
21         x=0;
22         for(int i=1;i<=la;i++)
23         {
24             c[i]=(x*10+a[i])/j;
25             x=(x*10+a[i])%j;
26         }
27         if(x==0)
28         {
29             tot++;
30             cout<<j<<" ";
31         }
32     }
33     if(tot==0)
34     {
35         cout<<"none";
36     }
37     /*int lc=1;
38     for(int i=1;i<=la;i++)
39     {
40         if(c[i]==0&&lc<la)
41         lc++;
42         else break;
43     }
44     for(int i=lc;i<=la;i++)
45     cout<<c[i];
46     cout<<endl;
47     cout<<x;*/
48     return 0;
49 }

 

posted @ 2017-03-16 19:29  自为风月马前卒  阅读(778)  评论(0编辑  收藏  举报

Contact with me