链接:​​https://www.nowcoder.com/acm/contest/67/I​​ 来源:牛客网

题目描述


    lulu喜欢小于等于1000的正整数,但是如果某个数是a或b的倍数,lulu会讨厌这个数。如果某个数里包含了a和b两个数里包含的数,lulu也会讨厌。(例如a=14,b=23,如果数字中包含1、2、3、4这四个数中的任意一个数,lulu就会讨厌这个数)。现在告诉你a,b,你能说出lulu喜欢的数有多少个么。



输入描述:



第一行是样例数T 第2到2+T-1行每行有2个整数a b。



输出描述:



输出lulu喜欢的数的个数



#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int a,b;
int map[10];
int che(int x)
{
if(map[x])return 1;
else return 0;
}
void ma(int x)
{
int w=x;
int ans=0;
while(w)
{
w=w/10;
ans++;
}

for(int i=1;i<=ans;i++)
{
int c;
c=x%10;
map[c]=1;
x=x/10;
}
if(x)map[x]=1;

}
int q(int x)
{
if(x%a==0||x%b==0)return 0;
int w=x;
int ans=0;
while(w)
{
w=w/10;
ans++;
}

for(int i=1;i<=ans;i++)
{
int c;
c=x%10;
if(che(c))return 0;
x=x/10;
}
if(che(x)&&x)return 0;

return 1;

}
int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
memset(map,0,sizeof(map));

cin>>a>>b;
ma(a);
ma(b);
int sum=0;
for(int i=1;i<=1000;i++)
{
if(q(i))sum++;
}
cout<<sum<<endl;
}

return 0;
}