Primality Test HDU7129
题目链接:Problem - 7129
Problem Description
A positive integer is called a prime if it is greater than 1 and cannot be written as the product of two smaller positive integers. A primality test is an algorithm for determining whether an input number is a prime. For example, the Miller-Rabin primality test is a probabilistic primality test. This problem is precisely the one about the primality test.
Let's define the function f(x) as the smallest prime which is strictly larger than x. For example, f(1)=2, f(2)=3, and f(3)=f(4)=5. And we use ⌊x⌋ to indicate the largest integer that does not exceed x.
Now given x, please determine whether g(x) is a prime.
g(x)=⌊f(x)+f(f(x))2⌋
Input
The first line of the input contains an integer T (1≤T≤105), indicating the number of test cases.
Each test case contains an integer x (1≤x≤1018) in a single line.
Output
For each test case, if g(x) is a prime, output YES in a single line. Otherwise, output NO in a single line.
Sample Input
2
1
2
Sample Output
YES
NO
题意:f(x) = 大于x的最小素数
然后判断g(x)是否为素数
思路:只有x==1的时候g(x)= 2 为素数
#include<bits/stdc++.h>
using namespace std;int main(){int t;cin >> t;while(t--){long long n;cin >> n;if(n == 1){cout << "YES" << endl;}else{cout << "NO" << endl;}}return 0;
}
Primality Test HDU7129相关推荐
- 米勒罗宾素性测试(Miller–Rabin primality test)
1 #include<iostream> //该程序为哥德巴赫猜(想输出所有的组合) 2 #include<cmath> 3 #include<cstdlib> 4 ...
- Primality Test 素数,打表
题意 :f(x)f(x)f(x)是严格大于x的最小质数,g(x)=[f(x)+f(f(x))]/2g(x)=[f(x)+f(f(x))]/2g(x)=[f(x)+f(f(x))]/2的向下取整,判断g ...
- 用 js判断 一个数是否是素数(质数)_2020-09-20:如何判断一个数是质数?
福哥答案2020-09-20:#福大大架构师每日一题# 1.试除法.朴素素数筛,埃氏筛,欧拉筛和区间筛.代码采用朴素素数筛. 2.费尔马素性测试法法.费马小定理:假如p是质数,a是整数,且a.p互质, ...
- 初等数论--同余--MILLER-RABIN素性检测算法优化
初等数论--同余--MILLER-RABIN素性检测算法优化 Euler theorem.Fermat's little theorem Primality Test: Fermat.MILLER-R ...
- 费马素性测试和米勒—拉宾素性测试
chapter 1 Fermat's little theorem 费马小定理 费马小定理说的是:如果p是一个素数,那么对于任意一个整数a,a p − a 能被p整除,也可以用模运算表示如下: (p是 ...
- 计算机常用编程英语词汇大全,计算机编程及常用术语英语词汇大全
第一部分.计算机算法常用术语中英对照 Data Structures 基本数据结构 Dictionaries 字典 Priority Queues 堆 Graph Data Structures 图 ...
- HDU 4548 美素数 素数题解
本题就是能够直接打表的,推断能否够打表也须要技巧的: 1 推断最大的数值为1000000.百万下面的数打表都是能够的 2 能够线性预处理好.使用素数筛子法是能够接近线性预处理的. 故此能够打表了. 须 ...
- fermat数推素数无穷_如何在3分钟内对Fermat测试进行素数测试
fermat数推素数无穷 The Fermat test is based on a result from number theory known as Fermat's little theore ...
- c语言专属英语单词,C语言 V 编程英语单词.doc
编程词汇英汉对照 Data Structures 基本数据结构 Dictionaries 字典 Priority Queues 堆 Graph Data Structures 图 Set Data S ...
最新文章
- hdu 5273 Dylans loves sequence 逆序数简单递推
- Java学习之Hello World 第一个小程序
- Python文件格式 .py .pyc .pyw .pyo .pyd的主要区别
- cocos2d基础介绍
- Linux系统编程8-18总结项目:完成一个简单的自己的shell
- mysql临时关闭查询日志_mysql故障排错临时打开通用日志和慢查询日志
- python播放音乐-python 模拟(简易)音乐播放器
- MongoDB C Driver使用教程
- AcWing提高算法课Level-3 第六章 基础算法
- SuperWebSocket发布0.1版本
- NIO+SocketChannel+Buffer+Selector 多路复用
- 安卓移动端appium环境搭建流程
- Terminating app due to uncaught exception ‘NSInvalidArgumentException‘
- linux基础的基础命令操作
- 吴恩达机器学习课程笔记(英文授课) Lv.1 新手村(回归)
- JSF 原理简要介绍
- vue 项目中使 实现粒子动态 背景图
- 使用百度云主机的GPU主机教程_第二部分
- mysql如何设置密码
- 百度贴吧测试部门实习生电话面试