1 条题解
-
0
C :
int len; int cmp(int a[],int k) {int i; for(i=0;i<len-1;i++) a[i+1]+=(a[i]%k)*10; if(a[i]%k==0) return 1; else return 0; } int main(int argc, char* argv[]) {char num[31]; int i,b[11],j,k,tem[31]; while(gets(num)) { if(num[0]=='-'&&num[1]=='1')break; len=strlen(num); j=0; for(k=2;k<10;k++) { for(i=0;i<len;i++) tem[i]=num[i]-'0'; if(cmp(tem,k)) b[j++]=k; } if(j==0)printf("none\n"); else for(i=0;i<j;i++) printf(j-i==1?"%d\n":"%d ",b[i]); } return 0; }
C++ :
#include <iostream> #include <string> using namespace std; bool isDiv(string s,int k){ int v = 0, r = 0; for(int i=0;i<s.length();i++){ v = (s[i]-'0') + r * 10; r = v%k; } if(r==0){ return true; } else{ return false; } } int main(){ string s; while(cin>>s){ if(s=="-1"){ return 0; } bool flag = true; for(int i=2;i<10;i++){ if(isDiv(s,i)){ if(flag){ cout<<i; } else{ cout<<" "<<i; } flag = false; } } if(flag){ cout<<"none"; } cout<<endl; } return 0; }
Java :
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =new Scanner(System.in); String cString =new String(); while(input.hasNext()) { cString=input.next(); int sum=0; if (cString.equals("-1")) { break; } BigInteger aBigInteger=new BigInteger(cString); BigInteger bigInteger =new BigInteger("2"); BigInteger cBigInteger=new BigInteger("0"); BigInteger dBigInteger=new BigInteger("1"); for (int i = 2; i <=9; i++) { if ((aBigInteger.mod(bigInteger)).equals(cBigInteger)) { sum++; if (sum==1) { System.out.print(i); } else { System.out.print(" "+i); } } bigInteger=bigInteger.add(dBigInteger); } if (sum==0) { System.out.print("none"); } System.out.println(); } } }
- 1
信息
- ID
- 1402
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者