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 ...
随机推荐
- OpenGL学习笔记(2) 画一个正方形
画一个正方形 其实,画正方形就是画两个三角形,用四个顶点以及使用索引来实现 完整代码在Square项目的Application.cpp里 先贴上窗口初始化代码 void BaseInit() { gl ...
- Python浮点算术:争议和限制
浮点数在计算机硬件中表示为以 2 为基数(二进制)的小数.举例而言,十进制的小数 0.125 等于 1/10 + 2/100 + 5/1000 ,同理,二进制的小数 0.001 等于0/2 + 0/4 ...
- navicat连接mysql出现1251错误
刚刚安装热乎的navicat发现出现1251错误,原因不大清楚,找到一个解决办法: 将mysql的密码重新重置一遍: 1.打开命令行 ,进入mysql所在的目录,输入 mysql -uroot -p ...
- 高可用OpenStack(Queen版)集群-17.一些问题
参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...
- impala 使用记录
在命令行里面直接输入类似下面的语句,就可以执行impala sql语句. impala-shell -q "select * from xxxc limit 10;" 当用pyth ...
- python基础网络编程--转
python之网络编程 本地的进程间通信(IPC)有很多种方式,但可以总结为下面4类: 消息传递(管道.FIFO.消息队列) 同步(互斥量.条件变量.读写锁.文件和写记录锁.信号量) 共享内存(匿名的 ...
- 笨办法学Python - 习题1: A Good First Program
在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...
- jQuery获取复选框选中的每一个值
$('input[name="serviceMode"]:checked').each(function(){ this.attr('value') });
- 作业1MathExam
自己取一个大气又可爱的标题 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 720 1000 ...
- web 08 struts2入门 struts2配置 struts包
电影网站:www.aikan66.com 项目网站:www.aikan66.com游戏网站:www.aikan66.com图片网站:www.aikan66.com书籍网站:www.aikan66.co ...