Little Elephant and Numbers(CF-221B)

Problem Description

The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.

Input

A single line contains a single integer x (1 ≤ x ≤ 109).

Output

In a single line print an integer — the answer to the problem.

Examples

Input

1

Output

1

Input

10

Output

2

题意:给出一个数 x,现在要寻找 x 的约数,对于每个约数,若其中的某一位与数 x 的某一位相同,则数量 +1,输出最后的数量

思路:先将 x 分解数位存在桶中,然后对 x 进行暴力,求解 x 的每一位约数,再对约数进行分解数位,看数位是否在桶中存在,需要注意的是,对于 25、36 这种数需要进行特判,因为 i*i=x 时,i 被统计了两次,需要-1

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int a[N];
void getBit(int temp){
    while(temp){
        a[temp%10]=1;
        temp/=10;
    }
}
bool judge(int temp){
    while(temp){
        if(a[temp%10])
            return true;
        temp/=10;
    }
    return false;
}
int main(){
    int n;
    scanf("%d",&n);
    getBit(n);

    int res=0;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            if(judge(i))
                res++;
            if(judge(n/i))
                res++;
        }
    }

    if(n==(int)sqrt(n)*(int)sqrt(n))
        if(judge((int)sqrt(n)))
            res--;

    printf("%d\n",res);

    return 0;
}

 

posted @ 2022-09-20 22:53  老程序员111  阅读(9)  评论(0)    收藏  举报