Codeforces Round #136 (Div. 2)——B

来源:互联网 发布:喷泉动画小软件 编辑:程序博客网 时间:2024/06/09 17:15

B. Little Elephant and Numbers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.

Input

A single line contains a single integer x (1 ≤ x ≤ 109).

Output

In a single line print an integer — the answer to the problem.

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int a[20];int b[20];int getnum(int x){    memset(b,0,sizeof(b));    int i=0;    while(x)    {        b[i++]=x%10;        x/=10;    }    return i-1;}int getn(int x){    memset(a,0,sizeof(a));    int i=0;    while(x)    {        a[i++]=x%10;        x/=10;    }    return i-1;}int main(){    int n,cnt=0,i,j,k;    scanf("%d",&n);    int lena=getn(n);    int p=sqrt(n);    if(n==1)    {        printf("1\n");        return 0;    }    for(i=1; i<=p; i++)        if(n%i==0)        {            int lenb=getnum(i);            int t=0;            for(j=0; j<=lena; j++)            {                for(k=0; k<=lenb; k++)                    if(a[j]==b[k])                    {                        cnt++;                        t=1;                        if(i*i==n) cnt--;                        break;                    }                if(t==1) break;            }            lenb=getnum(n/i);            t=0;            for(j=0; j<=lena; j++)            {                for(k=0; k<=lenb; k++)                    if(a[j]==b[k])                    {                        cnt++;                        t=1;                        break;                    }                if(t==1) break;            }        }    printf("%d\n",cnt);    return 0;}