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进行计算
相关文章推荐
- 左右选择小组件
- 《算法谜题》
- socket,
- boost教程
- 亲身经历故障--如何解决
- Node.js Cannot find module 'xxx' 问题解决
- c语言结构体用法
- 域用户查看应用的策略
- SRM144DIV1 Lottery
- [python]json.load() vs val()探究
- OJ_1124
- 计算相似度方法
- java 导出excel问题
- 使用nginx upstream upstream timed out while reading response header from upstream问题解决
- ios开发第三方库介绍大全(收集中)
- 《趣学Python编程》
- 浅谈windows句柄表
- poj 2002 Squares 几何二分 || 哈希
- 持续集成调研报告(1)
- OJ_1123 采药