zoukankan      html  css  js  c++  java
  • SJTU 3001. 二哥的幸运

    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
    ");
    		else printf("NO
    ");
    	}
    	return 0;
    }




  • 相关阅读:
    jstack使用教程
    频繁fullgc排查
    ubuntu添加ubuntu make
    Spring属性编辑器详解
    mysql 查看触发器,删除触发器
    mongodb启动不了:提示错误信息为 child process failed, exited with error number 100
    RedHat7 防火墙设置以及端口设置
    linux 设置静态IP方法
    linux 安装mongo
    mongo 介绍
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4197418.html
Copyright © 2011-2022 走看看