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 ...
随机推荐
- XSS分类&危害&防御
XSS(跨站脚本)漏洞是什么? 在网页中插入恶意的js脚本,由于网站没对其过滤,当用户浏览时,就会触发脚本,造成XSS攻击 XSS分类? 1.反射型 用户输入的注入代通过浏览器传入到服务器后,又被目标 ...
- 经典的性能优化最佳实践 web性能权威指南 读书笔记
web性能权威指南 page 203 经典的性能优化最佳实践 无论什么网络,也不管所用网络协议是什么版本,所有应用都应该致力于消除或减 少不必要的网络延迟,将需要传输的数据压缩至最少.这两条标准是经典 ...
- 使用AD对Linux客户端进行身份验证
https://technet.microsoft.com/zh-cn/library/2008.12.linux.aspx
- 51nod-1298 圆与三角形(计算几何超详解)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1298 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是 ...
- 使用NNI的scikit-learn以及Tensorflow分析
一.NNI简介 NNI (Neural Network Intelligence) 是自动机器学习(AutoML)的工具包. 它通过多种调优的算法来搜索最好的神经网络结构和(或)超参,并支持单机.本地 ...
- watch命令详解
基础命令学习目录首页 原文链接:https://www.cnblogs.com/kaishirenshi/p/7727986.html watch 命令详解: author:headsen chen ...
- 深入 JSX
从本质上讲,JSX 只是为 React.createElement(component, props, ...children) 函数提供的语法糖.JSX代码: 1 2 3 <MyButton ...
- [leetcode-897-Increasing Order Search Tree]
Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root o ...
- Notes of Daily Scrum Meeting(11.8)
Notes of Daily Scrum Meeting(11.8) 预备中开始写代码的第一天,因为大家对Android编程的熟悉程度还是不够,所以工程进行的非常缓慢,有四名队员 开始编写自己的任务, ...
- Linux 目录结构及文件基本操作
Linux 目录结构及文件基本操作 实验介绍 1.Linux 的文件组织目录结构. 2.相对路径和绝对路径. 3.对文件的移动.复制.重命名.编辑等操作. 一.Linux 目录结构 在讲 Linux ...