codeforces 221B Little Elephant and Numbers

来源:互联网 发布:怎样做app软件 编辑:程序博客网 时间:2024/05/18 03:06

       题目的意思是说给定一个数x,找到满足情况(d是x的约数,且d和x有至少一个相同的数字)d的个数,直接模拟就可以了。

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){     int n,m,i,j;     int ans=0;     int a[10];     memset(a,0,sizeof(a));     scanf("%d",&n);     m=n;     while(n)     {         a[n%10]++;         n/=10;     }     for(i=1;i*i<=m;i++)     {         if(m%i==0)         {             j=i;             while(j)             {                 if(a[j%10])                 {ans++;break;}                 j/=10;             }             j=m/i;             if(i*i!=m)                 while(j)             {                 if(a[j%10])                 {ans++;break;}                 j/=10;             }         }     }     if(m==1) printf("1\n");     else     printf("%d\n",ans);    return 0;}


 

0 0
原创粉丝点击