Gauss Prime UVA - 1415
题意:给出a和b判定是否为高斯素数
解析:
普通的高斯整数i = sqrt(-1)
高斯整数
是素数当且仅当:
a、b中有一个是零,另一个是形为
或其相反数
的素数;
或a、b均不为零,而
为素数。
这题 提取出sqrt(2) 就和普通情况一样了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std; int main() {
int t, a, b;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &a, &b);
int ok = ;
if(a == || b ==)
{
if(a == && b == )
{
cout<< "No" <<endl;
continue;
}
int temp;
if(a == )
temp = b;
else
temp = a;
if(temp%)
{
cout<< "No" <<endl;
continue;
}
else
{
temp -= ;
for(int i=; i<=sqrt(temp + 0.5); i++)
if(temp % i == )
{
cout<< "No" <<endl;
ok = ;
break;
}
if(!ok) printf("Yes\n");
} }
else
{
int flag = ;
ll x = a*a + *b*b;
for (int i = ; i <= sqrt(x+0.5); i++)
if (x % i == ) {
printf("No\n");
flag = ;
break;
}
if (!flag)
printf("Yes\n");
} }
return ;
}
Gauss Prime UVA - 1415的更多相关文章
- uva 1415 - Gauss Prime(高斯素数)
题目链接:uva 1415 - Gauss Prime 题目大意:给出一个a,b,表示高斯数a+bi(i=−2‾‾‾√,推断该数是否为高斯素数. 解题思路: a = 0 时.肯定不是高斯素数 a != ...
- UVA 1415 - Gauss Prime(数论,高斯素数拓展)
UVA 1415 - Gauss Prime 题目链接 题意:给定a + bi,推断是否是高斯素数,i = sqrt(-2). 思路:普通的高斯素数i = sqrt(-1),推断方法为: 1.假设a或 ...
- UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers
题意: 给出n,求把n写成若干个连续素数之和的方案数. 分析: 这道题非常类似大白书P48的例21,上面详细讲了如何从一个O(n3)的算法优化到O(n2)再到O(nlogn),最后到O(n)的神一般的 ...
- UVA - 524 Prime Ring Problem(dfs回溯法)
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...
- UVA 10200 Prime Time 水
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 10200 Prime Time【暴力,精度】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- UVA P12101 【Prime Path】
题库 :UVA 题号 :12101 题目 :Prime Path link :https://www.luogu.org/problemnew/show/UVA12101
- UVa 524 Prime Ring Problem(回溯法)
传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...
随机推荐
- 使用Nmon_Analyzer excel 问题总结
使用wps打开nmon的分析文件,出现 运行时错误13类型不匹配 查看具体代码,是这句出现错误Start = DateValue(Sheet1.Range("date")),进一 ...
- Intellij IDEA创建maven项目无java文件问题
在idea开发工具中创建工程时,点击右键没有创建包.接口.java类的提示, 如图: 解决之前的项目目录为: 针对这种情况,对idea开发工具做以下设置. 选择File->Project Str ...
- OpenFastPath(2):原生态Linux Socket应用如何移植到OpenFastPath上?
版本信息: ODP(Open Data Plane): 1.19.0.2 OFP(Open Fast Path): 3.0.0 1.存在的问题 OpenFastPath作为一个开源的用户态TCP/IP ...
- php从入门到放弃系列-02.php基础语法
php从入门到放弃系列-02.php基础语法 一.学习语法,从hello world开始 PHP(全称:PHP:Hypertext Preprocessor,即"PHP:超文本预处理器&qu ...
- SmartRaiden 和 Lighting Network 进行去中心化跨链原子资产交换
作者介绍 虫洞社区·签约作者 steven bai 前言 如果能够进行以太坊和比特币跨链原子资产交换,是不是一件很酷的事情? 目前链下的扩容方式有很多,最广为人知的就是比特币的闪电网络和以太坊的雷电网 ...
- 【一】,python简单爬虫实现
一: 1.获取当前页的课程名称,地址:https://www.ichunqiu.com/courses/webaq 2.选取其中一门课程名称查看源代码: 代码如下: <p class=" ...
- Redis Jedis简介
Redis是一种基于内存类型的数据存储工具 Jedis是一个用java写的Redis数据库操作的客户端,通过Jedis,可以很方便的对redis数据库进行操作.Jedis通过Jedis Pool进行R ...
- Python序列之列表 (list)
作者博文地址:http://www.cnblogs.com/spiritman/ 列表是Python中最基本的数据结构,是Python最常用的数据类型.Python列表是任意对象的有序集合,通过索引访 ...
- [redis] 几种redis数据导出导入方式
环境说明: 172.20.0.1 redis源实例 172.20.0.2 redis目标实例 172.20.0.3 任意linux系统 一.redis-dump方式 1.安装redis-dump工具 ...
- Linux下oracle启动/关闭监听(bash:lsnrctl:command not found)
打开终端 切换帐户 # su - Oracle 启动监听 $ lsnrctl start 关闭监听 $ lsnrctl stop 切换帐户一定要加 "-" 否则会出现: bas ...