Such numbers are called Vampire Numbers. More precisely, a number v is a Vampire Number if it has a pair of factors, a and b, where a*b=v, and together, a and b have exactly the same digits, in exactly the same quantities, as v. None of the numbers v, a or b can have leading zeros. The mathematical definition says that v should have an even number of digits and that a and b should have the same number of digits, but for the purposes of this problem, we’ll relax that requirement, and allow a and b to have differing numbers of digits, and v to have any number of digits. Here are some more examples:
126 = 6 * 21
10251 = 51 * 201
702189 = 9 * 78021
29632 = 32 * 926
Given a number X, find the smallest Vampire Number which is greater than or equal to X.
10 126 127 5000 0
126 126 153 6880
#include<bits/stdc++.h>
using namespace std;
int m[800],cnt=0;
int main()
{
set<int>vn;
for(int i=2;i<=1010;i++)
for(int j=i;i*j<=1000500;j++)
{
int vis[10]={0},x=i,y=j,s=i*j,flag=1;
while(x){vis[x%10]++;x=x/10;};
while(y){vis[y%10]++;y=y/10;};
while(s){vis[s%10]--;s=s/10;};
for(int k=0;k<=9;k++)
if(vis[k])
{
flag=0;
break;
}
if(flag) m[cnt++]=i*j;
}
sort(m,m+cnt);
int n;
while(cin>>n&&n!=0)
{
cout<<m[lower_bound(m,m+cnt,n)-m]<<endl;
}
return 0;
}
1124



被折叠的 条评论
为什么被折叠?



