codeblocks B - Little Elephant and Numbers

#include <bits/stdc++.h>

using namespace std;
#define eps 1e-8

int n, a[11];
vector<int> v;

int main()
{
    memset(a, 0, sizeof(a));
    cin>>n;
    int m = sqrt(n + 0.5);
    for(int i = 1; i <= m; i++)
    if(n % i == 0)
    v.push_back(i) , v.push_back(n/i);
    
    while(n)
    {
        a[n%10] = 1;
        n /= 10;
    }

    sort(v.begin() , v.end());
    v.erase(unique(v.begin() , v.end()) , v.end());
    int cnt = 0;
    for(int i = 0; i < v.size(); i++)
    {
        while(v[i])
        {
            if(a[v[i]%10])
            {
                cnt++ ;
                 break;
            }
            v[i] /= 10;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

你可能感兴趣的:(ACM,codeforces)