Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.
The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).
47
YES
16
YES
78
NO
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[1010];
void s(int p)
{
int i,t,x,j;
for(i = p; i < 1001; i++) //找到所有幸运数字
{
if(a[i] == 1) //如果这个数字已经被标记过则跳过
{
continue;
}
else
{
if(i%4==0 || i%7==0) //能被4或者7整除的时幸运数字
{
a[i] = 1;
j = 2;
while(1) //能被这个幸运数字整除的数字也为幸运数字
{
t = i*j;
if(t > 1000)
{
break;
}
else
{
a[t] = 1;
}
j++;
}
}
else
{
j = i;
while(j!=0) //由7和4组成的数字为幸运数字
{
x = j%10;
j = j/10;
if(x == 7 || x == 4)
{
a[i] = 1;
}
else
{
a[i] = 0;
break;
}
}
if(a[i] == 1)
{
j = 2;
while(1)
{
t = i*j;
if(t > 1000)
{
break;
}
else
{
a[t] = 1;
}
j++;
}
}
}
}
}
return ;
}
int main()
{
int n;
memset(a,0,sizeof(a));
s(4);
while(scanf("%d",&n)!=EOF)
{
if(a[n] == 1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}