uva1415 - Gauss Prime 高斯素数

【学习笔记】高斯整数、高斯素数、费马平方和(全部相关概念及例题详解)《初等数论及其应用》 【学习笔记】高斯整数(全部相关概念及例题详解) 阅读详情

In the late 1700s', Gauss, a famous mathematician, found a special kind ofnumbers. These integers are all in the form: a + b$ \sqrt{​{-k}}$.The sum and multiplicationofthese integers can be naturally defined as the follows:


(a + b$ \sqrt{​{-k}}$) + (c + d$ \sqrt{​{-k}}$) = (a + c) + (b + d )$ \sqrt{​{-k}}$


(a + b$ \sqrt{​{-k}}$) * (c + d$ \sqrt{​{-k}}$) = (a * c = b * d * k) + (a * d + b * c)$ \sqrt{​{-k}}$


One can prove that the sum and multiplication of these integers constitute thestructure called ``imaginary quadratic field" in calculus.

In case k = 1, these are common complex numbers.

In case both a and b are integers, these numbers are called ``Gauss integers", andthis is the very case that interests people the most in quadratic algebra.

As we all know that every integer can be factorized into the multiplication ofseveral primes (Fundamental theoorem of arithmetic, or unique factorization theorem).

Primes are the integers that can only be divided by 1 and itself. We do have asimilar concept in the context ofGauss integer.

If a Gauss integer cannot bee factorized into the multiplication of other Gaussintegers (0, 1, -1 exclusive), we call it a ``Gauss Prime" or ``Non-divisible".

Please note that 0, 1 and - 1 are not regarded as gauss primes but $ \sqrt{​{-k}}$ is.

However, unique factorization theorem doesn't apply to arbitrary k. For examplein the case k = 5, 6 can be factorized in two different ways:6 = 2 * 3, 6 = (1 + $ \sqrt{​{-5}}$) * (1 - $ \sqrt{​{-5}}$).

Thanks to the advance of mathematics in the past 200 years, one can prove thatthere are only 9 integers can be used as k, such that the unique factorization theoremsatisfies. These integers are k = { 1, 2, 3, 7, 1 1, 19, 43, 67, 163}.

Input 

The first line of the input is an integer n (1 < n < 100), followed by n lines. Each line is a single case and contains two integers, a and b (0$ \le$a$ \le$10000, 0 < b$ \le$10000).

Output 

To make this problem not too complicated, we just suppose that k is 2.

For every case of the input, judge whether a + b$ \sqrt{​{-2}}$ is a gauss prime.

Output the answer `Yes' or `No' in a single line.


Sample Explanation

Please notes that (5, 1) is not a gauss prime because (5, 1) = (1, -1) * (1, 2).

Sample Input 

2
5  1
3  4

Sample Output 

No
Yes

高斯整数a+bi是素数当且仅当:

  • a、b中有一个是零,另一个是形为4n+3或其相反数-(4n+3)的素数;
  • 或a、b均不为零,而a^2+b^2为素数。

  证明 点击打开链接

  这里是a+b√-2,因为素数不一定是高斯素数,当a=0或b=0时,素数也有可能分解成(a+b√-2)*(a-b√-2)(素数如果能分解,只能是这种形式),费马定理不能用了,就暴力看有没有b=x*x+2*y*y。

  如果a,b都不为零,就判断(a+b√-2)*(a-b√-2)=a*a+2*b*b是不是素数。如果是就不能分解,不是就能分解。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define eps 1e-9
#define MAXN 30010
#define MAXM 110
#define MOD 999983
typedef long long LL;
using namespace std;
int T,K;
int is_prime(int x){
    for(int i=2;i*i<=x;i++) if(x%i==0) return 0;
    return 1;
}
int check(int a,int b){
    if(!a){
        if(!is_prime(b)) return 1;
        int sq=sqrt(b)+0.5;
        for(int i=0;i<=sq;i++){
            double t=sqrt((b-i*i)/2.0);
            if(floor(t)==ceil(t)) return 1;
        }
        return 0;
    }
    if(is_prime(a*a+2*b*b)) return 0;
    return 1;
}
int main(){
    freopen("in.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        int a,b;
        scanf("%d%d",&a,&b);
        if(!check(a,b)) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}



高斯整数、高斯素数、费马平方和定理 本文主要对高斯整数、高斯素数、费马平方和定理进行介绍。 阅读详情

相关推荐

微信小程序音视频通话(for硬件)授权与设备注册实战指南

本文详细介绍了微信小程序音视频通话(for硬件)组件的开发实践,涵盖授权流程、设备注册与VoIP插件集成。重点解析了如何通过服务端获取snTicket实现用户授权,确保硬件设备与微信端的音视频通话安全可靠,适用于智能门禁、话机等物联网场景。

u6v7w8x的博客 945

高斯素数判定

​ 对于复数zabiz = a + bizabi,定义zzz的共轭为zˉa−bizˉa−bi23i12i2+3i,1+2i23i12i等等,对应着复平面上的整点。​ (若将i−1i−1​,替换为i−ki−k​,这样的数也叫高斯整数,但不一定满足整数唯一分解定理,现如今数学家们已经证明当且仅当k1237111967163k1237111967163时整数唯一分解定理成立)

zml19136706515的博客 1668

Orbbec-Gemini-335 深度相机 Python SDK 编译与配置全记录(Windows 环境)

本篇博客将围绕 Windows 系统下 Orbbec SDK 的 Python 配置与编译过程进行详细说明,主要使用的是官方提供的 pyorbbecsdk Python wrapper 项目以及 Orbbec SDK V2 Python Wrapper 配置指南,并记录了安装与配置过程中遇到的若干问题及解决办法。

Junseer的博客 1963

浅谈高斯素数([HAOI2008]圆上的整点)

只能研究到这一步了,剩下的要从头学习Min_25筛了

偶耶的博客 1594

搭建适用于lammps中opls-aa力场的文件流程

现在我已经解决了以上问题,并且通过我的方法可以实现从空白文档到搭建完成以上全部内容,后期只要细心检查即可。需要的data文件最关键是获得相应阴阳离子的mmol文件,因此问题转化为构建一份mmol文件。主要用到的软件及程序:gaussian09,makemol程序(tranal),opls-aa的参数文件。二面角个数:成角原子序号及对应的参数(这里PF6的结构没有二面角,所以为0)参考文献个数:文献名(空够行数即可,这些是给自己的备忘))和自身体系对应的参考文献,修改或填入对应的参数即可。

baguette的博客 2886

STM32驱动AS5600磁性旋转位置传感器模块

文章目录简介引脚定义I2C接口写数据读数据从指定的地址开始读数据驱动程序cubeMX配置驱动程序`bsp_as5600.h``bsp_as5600.c`测试程序参考资料 简介 AS5600 是一款易于编程的磁性旋转位置传感器,具有高分辨率 12 位模拟或 PWM 输出。 这种非接触式系统测量径向磁化轴上磁铁的绝对角度。 该 AS5600 专为非接触式电位计应用而设计,其坚固的设计消除了任何同质外部杂散磁场的影响。 引脚定义 I2C接口 7位设备地址为0x36(二进制表示为0110110) 支持标准模式和

ApexYuan 1万+

【代数学5】理想的分解:高斯整数环中理想的结构,并根据其范数和素数的性质进行分解

这些分解展示了在高斯整数环中理想的结构,以及如何根据其范数和素数的性质进行分解。 1. 求出范为1,2,3,4,5的全部理想; 2. 求出主理想(2),(3),(4),(5)的素理想分解。

定期分享我的发现和想法,感谢你的陪伴和支持 4282

Mission Planner连接Autopilot保姆级教程:从USB到无线全搞定

本文提供Mission Planner连接Autopilot的全面指南,涵盖USB直连、无线数传、蓝牙适配等多种连接方案。详细讲解驱动安装、波特率匹配、性能优化等关键步骤,并分享多链路冗余配置与故障转移的高阶技巧,助你快速解决连接问题。

weixin_28455801的博客 376

uva 1415 - Gauss Prime(高斯素数)

题目链接:uva 1415 - Gauss Prime 题目大意:给出一个a,b,表示高斯数a+bi(i=−2‾‾‾√,判断该数是否为高斯素数。 解题思路; a = 0 时,肯定不是高斯素数a != 0时,判断a2+2b2是否为素数即可。 #include #include #include bool is_prime (int n) { int m = sqr

不慌不忙、不急不躁 3097

【OpenSearch】从零到一:手把手搭建OpenSearch与Dashboard可视化平台

本文提供了一份详细的OpenSearch与Dashboard可视化平台从零搭建指南。内容涵盖环境准备、系统调优、核心服务安装配置、Dashboard部署与汉化,以及生产环境安全加固建议,帮助用户快速构建一个功能完整的搜索与分析平台。

devops8pract的博客 617

硬件测试之—纹波测试为什么不要使用接地夹子

示波器为什么不推荐使用接地夹

qq_19294353的博客 2988

UVA - 1415 Gauss Prime(高斯素数)

题目链接:点击查看 题目大意:给出一组a和b,判断a+b*sqrt(-2)是不是高斯素数 题目分析:对于一般的复数a+b*i,我们判断其为高斯整数的条件为a和b都为整数即可 而判断其为高斯素数的条件是,它不能再分解为其他高斯整数的乘积(0,1,-1除外),因为0,-1和1不能被视为高斯素数,但在这个题目中sqrt(-2)是高斯素数 所以高斯素数有以下两个性质: 如果一个素数,那么该素数p...

Falcon的博客 1282

汽车IVI中控开发入门及进阶(三):概述

开发板的作用当然是为了解决一些应用而设计的,主体是板,终极目的是应用,中间过程则是开发,是基于板的开发。可以和编译Linux内核一样,通过buildroot配置,menuconfig修改,编译出一个完整的可以直接烧写到芯片上运行的Linux系统软件(包含boot、kernel、rootfs以及rootfs中的各种库和应用程序)。所以这些实现都是建构在汽车中控开发板的解决方案上的,最核心的当然就是一颗中控主控芯片,这是一颗国产中控双核DA主控芯片,AECQ100认证的车规级芯片。Q:uboot的作用是什么?

码农17年的博客 1406

UVA 1415 - Gauss Prime(数论,高斯素数拓展)

UVA 1415 - Gauss Prime 题目链接 题意:给定a + bi,判断是否是高斯素数,i = sqrt(-2)。 思路:普通的高斯素数i = sqrt(-1),判断方法为: 1、如果a或b为0,判断另一个数为4 * n + 3形式的素数(用到费马平方和定理) 2、如果a、b都不为0,判断a ^ 2 + b ^ 2 是否为素数 那么这题,提取出sqrt(2)

Remilia's 1753

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

UVA 1415 Gauss Prime(高斯素数)

题意:判断a+b*sqrt(-2)是否为素数 解法:参考高斯素数的定义即判断方法 http://zh.wikipedia.org/wiki/高斯整數#include<stdio.h>

acmer的随记 638

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

UVA - 1415 Gauss Prime

Description In the late 1700s', Gauss, a famous mathematician, found a special kind of numbers. These integers are all in the form: a + b .The sum and multiplication ofthese integers can be natura

那些年 1090

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Gauss Prime UVA - 1415

题意:给出a和b判定是否为高斯素数 解析: 普通的高斯整数i = sqrt(-1) 高斯整数是素数当且仅当: a、b中有一个是零,另一个是形为或其相反数的素数; 或a、b均不为零,而为素数。 这题 提取出sqrt(2) 就和普通情况一样了 #include <iostream> #include <cstdio> #include <cstrin...

weixin_30376083的博客 84

数论基础讲解

数论,顾名思义,是对整数进行研究的理论。是数学学科的一个重要分支,也是ACM竞赛题型中饶有趣味的一个部分。   数论,有人戏称为“素论”。可见对于素数的研究在数论中比重之大。当然,也有不是对素数操作的算法,在这里我们也将其划归为数论。     1、整除:  1.1. 定义:   若a%b==0,则称a能被b整除或b能整除a,记作b | a.  1.2. 整除的性质:   (1)0可

xyjikl 3995

BZOJ 1041: [HAOI2008]圆上的整点 (高斯整数,高斯质数,圆上整点数)

引入一个函数:h(x)h(x)h(x) {h(x)=1,[x%4=1]h(x)=−1,[x%4=3]h(x)=0,[其它]\left\{\begin{matrix} &h(x) = 1 ,[x \% 4=1] \\ &h(x) = -1,[x \%4 = 3]\\ &h(x) = 0,[其它] \end{matrix}\right.⎩⎨⎧​​h(x)=1,[x%4=...

qq_41997978的博客 1017

【BZOJ1041】圆上的整点(数论)

题面 BZOJ 洛谷 题解 好神仙的题目啊。 安利一个视频,大概是第777到191919分钟的样子 因为要质因数分解,所以复习了一下Pollard_rhoPollard_rhoPollard\_rho #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstdlib&gt; #include&lt;cstr...

小蒟蒻yyb的博客 1173

[数论]高斯整数中的素数及费马平方和定理

<br /><br /><br /><br />注:这是从新浪网转载过来的<br />链接:http://blog.sina.com.cn/s/blog_6e3d28f70100n64y.html

TriSinker的专栏 2037

【学习笔记】浅谈高斯整数

OUYE 一下午自己找资料研究的成果,我花了一天去学。被 OUYE 卷飞了,可不是说着玩的。

七代目鸽影 3055
上一篇: hdu3892 Common Roots 最大取模公因式
下一篇: poj1436 Horizontally Visible Segments 线段树
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值