SJTU 3001. Lucky guy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.