【2018全国多校算法寒假赛】找数字个数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lujie_1996/article/details/79123808
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述

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喜欢的数的个数

示例1

输入
3
2 3
14 23
1234 5678

输出
171
190
7

说明

a=1234 b=5678的时候,只考虑含有数字9,0的数,只有7个,分别是9,99,999,90,990,909,900


备注

对于100%的数据,
0 < T <= 20;
0 <= a <= 99999;

0 <= b <= 99999。


代码

#include <stdio.h>
#include <string.h>
int main(void)
{
	int t;
	scanf("%d", &t);
	while(t --)
	{
		int a,b;
		scanf("%d%d", &a, &b);
		int mem[10];
		memset(mem, 0, sizeof(mem));
		int aa = a;
		int bb = b;
		while(aa)
		{
			mem[aa%10] = 1;
			aa /= 10;
		}
		while(bb)
		{
			mem[bb%10] = 1;
			bb /= 10;
		}
		int cnt = 0;
		for(int i = 1; i < 1001; i ++)
		{
			if(i%a && i%b)
			{
				int temp = i;
				int flag = 0;
				while(temp)
				{
					if(mem[temp % 10] != 1)
					{
						temp /= 10;
					}
					else
					{
						flag = 1;
						break;
					}
				}
				if(!flag)
				{
					cnt ++;
				}
			}
		}
		printf("%d\n", cnt);
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/lujie_1996/article/details/79123808