码迷,mamicode.com
首页 > 其他好文 > 详细

SJTU 3001. 二哥的幸运

时间:2015-01-01 18:31:07      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

Description

二哥是一个挺二的人,在二哥的世界观中,有些数字代表着幸运,假设在某一天二哥可以看到一个幸运数字,那么他将很高兴。当然,二哥对于幸运的定义也是不同凡响,假设一个数字仅仅包括4或者7两种字符,而且他是一个质数(素数),那么二哥觉得他是一个幸运数字。二哥想请聪明的你帮忙回答,给定的一个数是否是幸运数字。

Input Format

第1行有1个整数N,表示要測试的数据

Output Format

输出一行字符串,YES或者NO。 表示是否是个幸运数字

Sample Input

47

Sample Output

YES

例子解释

质数的定义为仅仅能被1和他本身整数的数。2是最小的质数。

数据范围

对于100%的数据: 1N1000000

思路:比較水的题

#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. 二哥的幸运

标签:

原文地址:http://www.cnblogs.com/gcczhongduan/p/4197418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!