[CF从零单排#13]122A - Lucky Division
Posted gdgzliu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[CF从零单排#13]122A - Lucky Division相关的知识,希望对你有一定的参考价值。
题目来源: http://codeforces.com/problemset/problem/122/A
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.
Input
The single line contains an integer n (1?≤?n?≤?1000) — the number that needs to be checked.
Output
In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).
Examples
input
47
output
YES
input
16
output
YES
input
78
output
NO
Note
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.
题目大意:
数字4,7都是幸运数字。如果一个整数只包含幸运数字,那么它是幸运数,显然幸运数字本身也是幸运数。另外如果一个整数,它能被幸运数整数,它也是幸运数。现在输入一个整数n,n<=1000。问它是否是幸运数,是的话输出YES,否则输出NO。
题目分析:
打表的思想。很显然在1000以内的只含有幸运数字的数只有14个:4,7, 44, 47, 74, 77,444, 447, 474, 477, 744, 747, 774, 777。那么只需要把这些书存到数组中,如果一个数能被这些数的某个数整除,那么就是幸运数,否则就不是。
参考代码:
#include <bits/stdc++.h>
using namespace std;
int main(){
int a[14] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777};
int n;
cin >> n;
bool flag = false;
for(int i=0; i<14; i++){
if(n%a[i]==0){
flag = true;
break;
}
}
if(flag)
cout << "YES";
else
cout << "NO";
return 0;
}
以上是关于[CF从零单排#13]122A - Lucky Division的主要内容,如果未能解决你的问题,请参考以下文章