Welcome to Liukejie's |

liukejie

园龄:1年8个月粉丝:5关注:11

2023-07-01 10:28阅读: 4评论: 0推荐: 0

CF221B Little Elephant and Numbers 题解

思路

按题意模拟即可。

1n 之间寻找 n 的因数,如果 in 的因数,那么 n÷i 一定也是 n 的因数,再判断 in÷i 是否与 x 含有共同数字。如果有,则方案数加一。

注意:如果 in÷i 是相同的数字,则要去重。

#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int x, ans, t; 
bool check(int n)
{
	memset(b, 0, sizeof b);
	for(; n;) b[n % 10] = 1, n /= 10;
	for(int i = 0; i < 10; ++ i)
		if(a[i] && b[i])
		    return 1;
	return 0;
}
main()
{
	cin >> x;
	t = x;
	for(; t;) b[t % 10] = 1, t /= 10;
	for(int i = 1; i <= x / i; ++ i)
		if(x % i == 0)
		{
            ans += check(i);
            if(x / i != i)
                ans += check(x / i);
        }
	cout << ans;
	return 0;
}

posted @   liukejie  阅读(4)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起