POJ 3641 Pseudoprime numbers

akshare 布林通道策略 import datetime import pandas as pd import backtrader as bt import matplotlib.pyplot as plt from datetime import datetime import matplotlib import akshare as ak %matplotlib inline class Boll_strategy(bt.Strategy): #自定义参数,每次买入1800手 params=(('size'. 阅读详情

Fermat’s theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, known as base-a pseudoprimes, have this property for some a. (And some, known as Carmichael Numbers, are base-a pseudoprimes for all a.)

Given 2 < p ≤ 1000000000 and 1 < a < p, determine whether or not p is a base-a pseudoprime.

Input

Input contains several test cases followed by a line containing “0 0”. Each test case consists of a line containing p and a.

Output

For each test case, output “yes” if p is a base-a pseudoprime; otherwise output “no”.

Sample Input

3 2
10 3
341 2
341 3
1105 2
1105 3
0 0

Sample Output

no
no
yes
no
yes
yes

题意描述:给出两个longlong范围的数p和a,如果a的p次幂对p取余且余数为a,则p的某些(但不是很多)非素数值,称为base-a伪素数。

解题思路:首先判断p是否为素数,如果p为素数输出no,否则继续判断a的p次幂,用快速幂的方法去求出a的p次幂对p取余的余数。

AC代码

#include<stdio.h>

bool prime(long long p)
{
	for(int i=2;i*i<p;i++)
		if(p%i==0)
			return 0;
	return 1;
}

long long cm(long long a,long long p)
{
	long long ans=1,res=a,mod=p;
	while(p!=0){
		if(p&1)
			ans=ans*res%mod;
		res=res*res%mod;
		p>>=1;
	}
	return ans%mod;
}

int main(void)
{
	long long a,p;
	while(~scanf("%lld%lld",&p,&a)){
		if(a==0&&p==0)
			break;
		if(prime(p)==1)
			printf("no\n");
		else if(cm(a,p)==a)
			printf("yes\n");	
		else
			printf("no\n"); 
	}
	return 0;
}
从零构建:Simulink与PX4的快速原型开发实战 本文详细介绍了如何利用Simulink与PX4进行四旋翼无人机的快速原型开发,涵盖环境搭建、动力学建模、控制器设计、仿真验证及自动代码生成全流程。通过实战案例展示姿态控制器的实现与调试,帮助开发者高效完成从算法设计到硬件部署,显著提升开发效率并降低试错成本。 阅读详情

相关推荐

使用CubeMX生成的项目在Keil下添加DSP库并包含arm_math头文件后报错的解决办法

问题描述: 最近使用Cube生成工程后,在Keil中使用Manage Runtime Environment即绿色小饼干按钮添加CMSIS的DSP库后编译报错。很有意思的是,STM32论坛上有外国朋友报告的同样的错误,都是30个Errors,5个Warning。 问题分析: 参考国内论坛某帖子(具体想不起来了),认为因该是Cube复制了库后,Keil从原始Packs目录下引用DSP库导致和Cub...

qq_32256951的博客 7001

【 POJ 3641 】Pseudoprime numbers

Pseudoprime numbersTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 8702 Accepted: 3658 DescriptionFermat’s theorem states that for any prime number p and for any integer a > 1, ap

Nodies 449

手把手教你用TL431设计反激电源补偿器(附波特图调试技巧)

本文详细介绍了如何使用TL431设计反激电源补偿器,并提供了波特图调试技巧。通过实战经验分享,帮助工程师快速掌握补偿网络设计、分压电阻计算和稳定性判据,避免常见设计误区,提升电源稳定性与效率。

weixin_29201859的博客 378

POJ 3641 Pseudoprime numbers

HPU专题训练(-1)GCD&amp;amp;&amp;amp;素筛&amp;amp;&amp;amp;快速幂_____K - Pseudoprime numbers题目来源http://poj.org/problem?id=3641第一次做的时候用的是int 没有用long long 范围比较小,出错了而且英文题目,还扯了费马小定理,百度了一下,但是也没用到写两个函数就行了,快速幂,素数判断/*...

鸿杰 的博客 517

GATK SNP过滤参数优化:从标准到个性化调整的实践指南

本文深入探讨了GATK SNP过滤参数的个性化调整策略,强调不应盲目套用官方标准参数。文章详细拆解了QD、FS、SOR等关键过滤参数的含义,并提供了通过数据分布分析、文献调研和迭代测试来确定适合自身数据(如动植物重测序)最佳阈值的实践方法,旨在帮助研究者在保留真实变异与剔除假阳性信号之间找到最优平衡。

weixin_29216049的博客 275

生成式引擎优化(GEO)全景指南:技术架构、实施策略与未来趋势

生成式引擎优化(GEO)全景指南摘要 GEO(生成式引擎优化)是针对AI生成内容(如ChatGPT、文心一言等)的优化策略,通过结构化数据、权威建设与语义优化提升企业内容在AI答案中的引用优先级,实现“无点击曝光”。其核心价值在于从流量竞争转向信任构建,突破传统SEO局限。技术架构依托RAG(检索增强生成)、向量数据库及反馈学习机制,动态优化内容生成与引用逻辑。实施策略包括:部署结构化数据(如JSON-LD)、维护动态知识图谱、适配多模态内容(3D/VR)、联合权威机构发布白皮书。行业案例显示,美妆、智能家

解锁AI流量新红利!🚀 GEO优化(生成引擎优化)助您掌控AI搜索,让AI成为您的品牌最佳代言人! 1451

poj-3641Pseudoprime numbers

poj-3641Pseudoprime numbers Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10836 Accepted: 4686 Description Fermat’s theorem states that for any prim

weixin_40433319的博客 261

两轮差速小车循线控制原理分析

硬件资料设定:小车驱动来自于两个相同的电机,转向依靠两轮差速实现,小车前后左右安装超声波传感器,前后各一个,左右各两个; 功能目标:假设小车左侧有墙壁,通过超声波测距实现按指定距离沿墙行驶 参数设定:车轮半径r=3cm,车轮间距wd=10cm,车身长length=16cm,侧边超声波传感器前后各一个,假设一个在车头一个在车尾,间距=车身=length=16cm,小车线速度恒定v = 0.2m/s,距离墙d=10cm,假设超声波传感器以10Hz的频率采集距离。 在以上条件下,设定小车出发点,方向与墙平行

aibingjin的博客 1万+

poj 3641 Pseudoprime numbers 【快速幂】

Pseudoprime numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6645   Accepted: 2697 Description Fermat's theorem states that for any prime number p a

shengweisong 2057

别再为UE5像素流部署踩坑了!Windows服务器单实例保姆级避坑指南(含Node.js证书、coturn空文件夹等常见问题解决)

本文提供了UE5像素流在Windows服务器单实例部署中的全面解决方案,涵盖Node.js证书过期、coturn空文件夹等常见问题。通过详细的步骤指导和配置建议,帮助开发者高效完成部署,避免常见陷阱,特别适合局域网环境下的应用场景。

weixin_30315435的博客 464

safetensors_rust.SafetensorError: Error while deserializing header: MetadataIncompleteBuffer解决方案

本文主要介绍了safetensors_rust.SafetensorError: Error while deserializing header: MetadataIncompleteBuffer解决方案,希望能对使用Python的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案 2.1 Windows 2.2 Linux

weixin_43178406的博客 15万+

POJ-3641 Pseudoprime numbers

题意:对于一个非素数p和任意一个数a,若a^p=a(mod p),则输出yes,否则输出no。 思路:判断素数+二分幂。 题目链接:http://poj.org/problem?id=3641 View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib...

bancaidun1539的博客 117

[SoC]SoC验证中bootcode与firmware相关验证经验总结

本文总结了SoC验证中bootcode和firmware的验证经验。重点介绍了两种数据加载方法:1)使用Verilog系统函数$readmemh/$readmemb直接写入ROM/ARAM,需注意文件路径、格式和斜杠方向;2)通过Memory Hierarchy在initial块中操作,需要添加适当延时并注意路径拼接。文章还提供了在testcase phase中先读取数据到HASH再写入SRAM的示例,并强调加载后需使能edc_bypass以避免ECC错误。验证过程中需特别注意文件位置、格式要求及路径处理等

元直的博客 2498

poj 3641 Pseudoprime numbers

题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for any prime numberpand for any integera> 1,ap=a(modp). That is, if we raisea...

dong12276的博客 147

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

POJ3641 Pseudoprime numbers

题目大意:就是如果P不是素数,能否满足ap =a (modp) 思路:直接素数判断+快速幂取模即可,我开始用的是普通素数判断,后来用了miller_rabin改进版的的素数测试,权当模板吧   AC program:(普通素数判断+快速幂) #include #include #include #include #include using namespace std; int p,a

muxi@Achilles的专栏 885

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

poj-3641(Pseudoprime numbers)

学习快速幂之后做的第一道题,这里记录一下。 题目大意:给出两个数 a 和 p,如果 p 是一个素数,判断是否满足公式 a^p %p=a,如果满足,则输出yes,否则,输出no。附链接:http://poj.org/problem?id=3641。 大体思路:题目简单,判断素数,然后判断是否满足公式。 以下是ac代码: #include using namespace std; long l

blackturtle的博客 427

深度学习工具包 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")

POJ 3641-Pseudoprime numbers

题目: 题意:

Halo 687

poj 3641 Pseudoprime numbers

Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8035 Accepted: 3341 Description Fermat's theo

※夏日星空※ 282

POJ 3641 Pseudoprime numbers(快速幂)

嗯... 题目链接:http://poj.org/problem?id=3641 AC代码: 1 #include<cstdio> 2 #include<iostream> 3 4 using namespace std; 5 6 inline bool is_prime(int x){ 7 if(x...

weixin_30408739的博客 334

POJ 3641.Pseudoprime numbers

数论方向的题目,最近开始做做这方面的简单题或者是模板题 题目大意: 根据费马定理,如果p是一个素数,则对任意数字a,有,现在,题目要求找出p[不是素数]时,满足此式的算式 题目链接 其中运用到了快速幂取模的操作(由于数字太过大),这大概也是第一次解决带有mod类型的题,虽然是个超级水题 = = 这种快速幂取模的方法是纯模拟方法,网上其他代码,例如用&判断奇偶的代码质量比我这个好很...

CuriousLiu的博客 333

POJ 3641 Pseudoprime numbers【素数+快速幂】

Pseudoprime numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8291   Accepted: 3471 Description Fermat's theorem states that for any prime number p a

希望的专栏 529

POJ-3641-Pseudoprime numbers

这个题要求求出若p不是素数并且p^a是否等于a,若等于则输出yes,否则输出no 这个题主要用到快速幂,其他就比较简单了 代码: #include #include #include using namespace std; bool ispri(long long num) { for(int i=2;i*i<num;i++) if(num%i==0) return f

z309241990的专栏 2230

POJ 3641 Pseudoprime numbers (数论+快速幂)

题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder...

G19850917的博客 187
上一篇: POJ 1700 Crossing River
下一篇: POJ 1083 Moving Tables
鳳九~
博客等级 码龄8年 1384粉丝 215原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值