您的位置:首页 > 其它

OJ_1125

2014-02-24 12:13 274 查看
#include <iostream>
#include <string>
using namespace std;
const int K=9;
bool candiv(int n,string s)
{
int inc=0;
for(int i=0;i<s.size();i++)
{
int temp=s[i]-'0'+inc*10;
inc=temp%n;

}
if(inc==0)return true;
return false;
}
void func()
{
string s;
while(cin>>s)
{
if(s=="-1")break;
int a[K+1];

for(int i=2;i<=K;i++)
{
if(candiv(i,s))
a[i]=i;
else
a[i]=-1;
}
int count=0;
for(int i=2;i<=K;i++)
{
if(a[i]==i)
if(count==0)
{
count++;
cout<<a[i];
}
else{
cout<<" "<<a[i];
}
}
if(count)
cout<<endl;
else
cout<<"none"<<endl;
}

}
int main(int argc, char *argv[])
{

//printf("Hello, world\n");
func();
return 0;
}


大数除法,只用考虑能否整除

题目描述:

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

输入:

若干个非负整数c,c的位数<=30

每行一个c,当c=-1时中止

(不要对-1进行计算!)

输出:

每一个c的结果占一行

1) 若存在满足 c%k == 0 的k,输出所有这样的k,中间用空格隔开,最后一个k后面没有空格。

2) 若没有这样的k则输出"none"

样例输入:
30
72
13
-1


样例输出:
2 3 5 6
2 3 4 6 8 9
none


提示:

注意整数溢出问题

不要对-1进行计算
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: