2208 - 价格
Input
第一行输入一个数T,表示测试数据个数,对于每组测试数据,输入一个整数n (0<=n<=10^9)
Output
对于每组测试数据,输出一个数,表示存在于n之中且n能被该数整除的一位数的个数
Examples
Input
4 12345 661232 52527 730000
Output
3 3 0 0
Hint
注意,除数不能为0,因此任何数不能被0整除。
第二个样例中1和2可以整除,由于有2个2,1个1,所以答案为3。
Solution C
#include<stdio.h> int main() { int T; scanf("%d",&T); while(T--) { int n,m,a; int s=0; scanf("%d",&n); int t=n; while(t) { m=t%10; if(m!=0) { a=n%m; if(a==0) s=s+1;} t=t/10; } printf("%d\n",s); } }
Solution C++
#include<stdio.h> int main() { int T,n,i,b,c; int a[10000]; scanf("%d",&T); while(T--) { scanf("%d",&n); b=n; for(i=1,c=0;b!=0;i++) { a[i]=b%10; b=b/10; if(a[i]==0) { c=c; } else if(n%a[i]==0) { c+=1; } } printf("%d\n",c); } return 0; }
Hint
注意,除数不能为0,因此任何数不能被0整除。
第二个样例中1和2可以整除,由于有2个2,1个1,所以答案为3。