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 ...
随机推荐
- android安卓生成密钥keystore(命令控制)
android安卓生成密钥keystore(命令控制) • 配置JDK 详细教程 https://blog.csdn.net/u012934325/article/details/73441617/ ...
- 180918-JDK之Deflater压缩与Inflater解压
JDK 压缩与解压工具类 在实际的应用场景中,特别是对外传输数据时,将原始数据压缩之后丢出去,可以说是非常常见的一个case了,平常倒是没有直接使用JDK原生的压缩工具类,使用Protosutff和K ...
- 初学者下载使用Python遇到的问题看它就行了
首先在python管网(www.python.org)中找到对应的版本与系统,以(window7系统64位python3.7.3为例) 打开电脑--打开浏览器--输入www.python.org--d ...
- windows系统下构建Jenkins持续集成
环境准备 windows10+tomcat+python3.x(安装方法自行百度) 安装Jenkins 从https://jenkins.io/download/ 下载war包 将war包放到tomc ...
- monkey测试入门1
Monkey是一款通过命令行来对我们APP进行测试的工具,可以运行在模拟器里或真机上.它向系统发送伪随机的用户事件流,实现对正应用程序进行压力测试. 官方介绍 :https://developer.a ...
- git push失败
不知道弄错了什么上传项目到github上失败 git commit的时候提示 On branch masternothing to commit, working tree clean git pus ...
- SVN For Mac: Cornerstone.app破解版免费下载
Cornerstone.app下载地址 链接:https://pan.baidu.com/s/1kwQ65SBgfWXQur8Zdzkyyw 密码:rqe7 Cornerstone303 MAS.a ...
- python多线程与GIL(转)
作者:卢钧轶(cenalulu) 本文原文地址:http://cenalulu.github.io/python/gil-in-python/ GIL是什么 GIL(Global Interprete ...
- 搭建Harbor私有镜像仓库--v1.5.1
搭建Harbor私有镜像仓库--v1.5.1 1.介绍 Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署我们私有环境 ...
- git查看添加删除远程仓库
查看远程仓库 git remote -v 删除远程仓库 git remote remove origin 添加远程仓库 git remote add origin 仓库地址 关联远程分支 重新关联远程 ...