找数字个数

链接: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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值