题意:求x所有约数的个数,要求约数里至少一个数字与x相同。
思路:先记录x中有哪些数字,然后枚举到sqrt(x)并判断。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int a[10];
int check(int x)
{
while (x)
{
if (a[x%10]==1)
return 1;
x/=10;
}
return 0;
}
int main(void)
{
memset(a,0,sizeof(a));
int x;
scanf("%d", &x);
int xx=x;
while (xx)
{
a[xx%10]=1;
xx/=10;
}
int ans =0;
if (x==1)
ans=1;
else
{
for (int i=1; i*i<=x; i++)
{
if (x%i==0)
{
if (check(i))
ans++;
if (x/i!=i)
if (check(x/i))
ans++;
}
}
}
printf("%d\n",ans);
return 0;
}