Description
The second brother is a very second man. In the second brother's world view, some figures represent luck. If one day the second brother can see a lucky number, then he will be very happy. Of course, the second brother's definition of luck is also extraordinary. If a number contains only four or seven characters and is a prime number, the second brother thinks that he is a lucky number. The second brother would like to ask you to help answer the question, whether the given number is a lucky number.
Input Format
The first row contains 1 integer N, indicating the data to be tested.
Output Format
Output a line of string, yes or no. Indicates whether it is a lucky number.
Sample Input
47
Sample output
YES
Example
The prime number is defined as a number that can only be 1 and its own integers. 2 is the smallest prime number.
Data range
For 100% of data: 1 ≤ n ≤1000000 ;
Train of Thought: Comparison
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>typedef long long ll;using namespace std;const int maxn = 1000005;int prime[maxn], vis[maxn], cnt;void init() {memset(vis, 0, sizeof(vis));vis[1] = vis[0] = 1;cnt = 0;for (ll i = 2; i < maxn; i++) {if (vis[i]) continue;prime[cnt++] = i;for (ll j = i*i; j < maxn; j += i)vis[j] = 1;}}int main() {int n; init();while (scanf("%d", &n) != EOF) {int flag = 1;int tmp = n;while (n) {if ((n%10) != 4 && (n%10) != 7) {flag = 0;break;}n /= 10;}if (flag && !vis[tmp])printf("YES\n");else printf("NO\n");}return 0;}
SJTU 3001. Lucky guy