UVA 10006 - Carmichael Numbers(快速幂取模)

【代码超详解】HDU 2138 How many prime numbers? 有多少个质数?(质数埃筛打表 + 判定,31 ms) 一、题目描述 How many prime numbers Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 27558 Accepted Submission(s): 9246(2019/11/11) Problem Descrip... 阅读详情

  Carmichael Numbers 

An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without cryptography. Alvaro is one of such persons, and is designing a set of cryptographic procedures for cooking paella. Some of the cryptographic algorithms he is implementing make use of big prime numbers. However, checking if a big number is prime is not so easy. An exhaustive approach can require the division of the number by all the prime numbers smaller or equal than its square root. For big numbers, the amount of time and storage needed for such operations would certainly ruin the paella.

However, some probabilistic tests exist that offer high confidence at low cost. One of them is the Fermat test.

Let a be a random number between 2 and n - 1 (being n the number whose primality we are testing). Then, n is probably prime if the following equation holds: 

\begin{displaymath}a^n \bmod n = a\end{displaymath}

If a number passes the Fermat test several times then it is prime with a high probability.

Unfortunately, there are bad news. Some numbers that are not prime still pass the Fermat test with every number smaller than themselves. These numbers are called Carmichael numbers.

In this problem you are asked to write a program to test if a given number is a Carmichael number. Hopefully, the teams that fulfill the task will one day be able to taste a delicious portion of encrypted paella. As a side note, we need to mention that, according to Alvaro, the main advantage of encrypted paella over conventional paella is that nobody but you knows what you are eating.

Input 

The input will consist of a series of lines, each containing a small positive number  n  (  2 <  n  < 65000). A number  n  = 0 will mark the end of the input, and must not be processed.

Output 

For each number in the input, you have to print if it is a Carmichael number or not, as shown in the sample output.

Sample Input 

1729
17
561
1109
431
0

Sample Output 

The number 1729 is a Carmichael number.
17 is normal.
The number 561 is a Carmichael number.
1109 is normal.
431 is normal.



============================

快速幂+素数判断


#include <iostream>
#include <cstdio>

using namespace std;

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

long long quick_mod(long long a,long long b,long long m)
{
    long long ans=1;
    a%=m;
    while(b)
    {
        if(b%2)
        {
            ans=ans*a%m;
            b--;
        }
        b/=2;
        a=a*a%m;
    }
    return ans;
}

int solve(int x)
{
    for(int i=2;i<x;i++)
    {
        if(quick_mod(i,x,x)!=i) return 0;
    }
    return 1;
}

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        //cout<<prime(n)<<" "<<solve(n)<<endl;
        if(!prime(n)&&solve(n))
            printf("The number %d is a Carmichael number.\n",n);
        else printf("%d is normal.\n",n);
    }
    return 0;
}


Quest 3开发第一步:搞定Meta账号登录和Oculus软件连不上设备的那些坑(2024实测) 本文详细介绍了Quest 3开发初期的关键步骤,包括Meta账号注册、Oculus软件安装与设备连接等常见问题的解决方案。针对国内开发者遇到的邮箱限制、验证码接收等难题,提供了实用的应对策略,并分享了开发环境配置和常见问题排查技巧,帮助开发者快速搭建Quest 3开发环境。 阅读详情

相关推荐

别再瞎调了!手把手教你用ADI IIO Oscilloscope配置AD936x的AGC(附Pluto SDR实测)

本文详细介绍了如何使用ADI IIO Oscilloscope工具配置AD936x系列射频捷变收发器的自动增益控制(AGC)功能,包括Slow/Fast Attack模式的参数设置与优化技巧。通过Pluto SDR硬件实测演示,帮助开发者快速掌握AGC配置方法,提升无线通信系统的接收性能。

weixin_30267785的博客 577

uvaoj 10006 Carmichael Numbers 快速幂取模

uvaoj 10006 Carmichael Numbers 快速幂取模

gwq5210的专栏 617

TX 的 LOL(Local Oscillator Leakage,本振泄露)

项目内容LOL 是什么本振残留在 TX 输出中心频率上的杂散主要原因IQ 失衡、硬件不完美、零中频架构影响杂散、干扰、性能劣化、安全问题解决方法初始化校准 + 跟踪校准(AD9371 支持)检测手段频谱仪、回环检测、ADC ILA 抓取。

weixin_41230430的博客 2046

UVA 10006

题目意思:快速幂求摸。。。。 G - Carmichael Numbers Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 10006 Description   Carmi

桑榆 1646

ZEMAX知识点:坐标间断面(coordinate break)

zemax知识点:坐标间断面

weixin_47638568的博客 1万+

嵌入式设备低功耗设计误区:为什么你的RK3568总是被‘意外’唤醒?

本文深入分析RK3568嵌入式设备低功耗设计中的常见误区,重点探讨唤醒源管理不当导致的意外唤醒问题。通过解析硬件设计陷阱、软件配置错误及系统化审计方法,帮助开发者有效排查和解决GPIO配置、唤醒源设置等关键因素引起的功耗异常,提升设备续航能力。

php55的博客 460

UVA 题目分类 (10000–10099)

10000  Longest Paths 最短路径   最短路径的变形,应用bellmanford算法 10001  Garden of Eden 搜索题目  直接搜索,Hash判重 10002  Center of Masses 重心计算  公式 10003  Cutting Sticks 动态规划  有些类似矩阵规划 10004  Bicoloring 并查集题  经典

iCpC之旅 1460

微信小程序 - 引入并使用 Fly.js 请求库(超级详细的教程及运行示例)提供 Fly.js 源码源文件下载,贴心的配置示例及注释,优雅快速的发起 http 网络请求

fly.js请求库官方教程文档,微信小程序封装fly.js请求,在小程序/mpvue中使用flyio发起网络请求的方法,微信小程序中如何使用flyio封装网络请求,微信小程序中如何使用flyio封装网络请求,最好的教程,fly最好的文档教程,微信小程序使用fly接口请求框架,引入fly.js报错,微信小程序中如何使用flyio封装网络请求,微信小程序引入Fly.js请求库,如何在fly中配置请求/响应拦截器,如何在微信小程序中优雅地发送异步请求,请求/响应拦截器,微信小程序-引入并使用F

🏆 前端领域优质创作者 5609

uva 10006 Carmichael Numbers

uva 10006 Carmichael Numbers

@fei 497

[STC32G144K246入门第三步]驱动串口收发(接收不定长数据)

本文介绍了STC32G144K246单片机的串口功能配置与使用。该芯片具有8组独立USART,支持异步/同步模式,各串口可独立配置波特率并支持DMA传输。重点讲解了串口寄存器配置方法,包括引脚设置、波特率计算和中断处理。特别指出RX引脚需配置为开漏或准双向口以避免接收乱码。还介绍了通过定时器实现不定长数据接收的技术方案,并提供了完整的初始化代码和中断处理函数示例。文中包含串口时序图、寄存器配置表等实用参考信息,适合嵌入式开发者快速上手多串口应用开发。

sinat_58149788的博客 195

黑猫带你学UFS协议第13篇:UFS初始化详解(Boot Operation)

本文详细解析了UFS设备的初始化过程,包括部分初始化、加载启动代码(可选)和初始化完成三个阶段。重点介绍了如何通过设备描述符和逻辑单元描述符配置引导特性,以及如何从UFS设备加载启动代码。内容适用于嵌入式硬件和存储领域的开发者。

黑猫奥利奥的博客 3555

Uva 10006 - Carmichael Numbers【素数+快速幂取模】

题意:输入一个数n,问你能否保证对于任意的a (2<a<n)使得 a^n%n==a 满足的话就是Carmichael number。 素数筛选+快速幂取模就可以了。 注意:虽然n在int范围内,但是进行幂运算以后就有可能超过int范围,所以要用long long。

AC_Dreameng 1084

【异常】Milvus 向量数据库字段缺失错误分析与解决 MilvusVectorStoreServiceV2 - Failed to insert batch [0-1]: The field:

本文分析了Milvus向量数据库插入操作中出现的字段缺失错误。错误显示age_mode字段未提供,导致批量插入失败。根本原因是Milvus Schema要求所有定义字段必须存在,但代码中对部分字段采用条件添加方式。解决方案是将条件添加改为始终添加,为可能为null的字段提供空字符串默认值。文章总结了Schema约束、防御性编程等经验,并建议通过Schema变更检查、单元测试覆盖和数据校验层等预防措施避免类似问题。该问题影响product、mac、source等多个字段,修改后确保了数据插入的可靠性。

奶爸的编程之路,也就一周冷个三天 407

UVA 10006 Carmichael Numbers(快速幂取模)

题意: 给定一个数n,如果这个数不是素数,并且满足 (a^n)mod n = a,则这个数叫做:Carmichael Numbers. 思路: (ab) mod c = ((a mod c) * (b mod c)) mod c. 利用这个性质,二分法快速幂取模。 AC代码#include <cstdio> #include <cstring> #include <algorithm>

小G的ACM之路 603

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

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

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

UVA 10006 - Carmichael Numbers(快速幂取模)

Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life

Remilia's 1191

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life

LYHVOYAGE的专栏 3049

UVa 10006 Carmichael Numbers(快速幂取模)

题意: 给定一个数n,如果这个数不是素数,并且满足 (a^n)mod n = a,则这个数叫做:Carmichael Numbers. 思路: (ab) mod c = ((a mod c) * (b mod c)) mod c. 利用这个性质,二分法快速幂取模。 #include <cstdio> #include <cstring> #inc...

weixin_30617561的博客 129

UVA 10006 Carmichael Numbers (暴力+快速幂取模)

#include #include using namespace std; typedef long long ll; int prime[70000]; void is_prime() { for(int i=2;i<=70000;i++) { if(!prime[i]) { for(int j=2*i;j<=70000;j+=i) prime[j]=1; } } }

AK_HuangYC的博客 525

UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

  Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and th...

weixin_34290000的博客 616

UVa 10006 Carmichael Numbers

/* File: 10006.cpp Author: ACboy Date: 2010-4-22 Result: AC Descripition: UVa 10006 Carmichael Numbers*/#include using namespace std;int vis[70000];// 快速幂取模(a^b % n)unsigne

个人独立博客http://www.acb0y.cn/ 1232

UVA 10006 Carmichael Numbers (快速幂取模+素数筛)(卡迈克尔数)

Sample Input 1729 17 561 1109 431 0 Sample Output The number 1729 is a Carmichael number. 17 is normal. The number 561 is a Carmichael number. 1109 is normal. 431 is normal.   卡迈克尔数:对于...

weixin_43841060的博客 344

UVa 10006 Carmichael Numbers (快速幂运算)

快速幂运算---反复平方法 /* *   [题意] *   输入n,若满足如下两个条件,则n是Carmichael number *       1、n不是素数 *       2、对于所有a(2 * *   [解题方法] *   快速幂取模,注意运算过程中的乘法溢出int */ #include using namespace std; typedef long

MADE_Y 1391

Uva 10006 Carmichael Numbers (快速幂)

照题意implemente就好~  然后快速幂~  AC代码如下: // // Uva 10006 Carmichael Numbers // // Created by TaoSama on 2015-03-24 // Copyright (c) 2015 TaoSama. All rights reserved. // #include #include #include #i

TaoSama's Microcosm 554

UVA - 10006 - Carmichael Numbers (快速幂+素数判断)

题目传送:UVA - 10006 思路:就是快速幂暴力过去就行了,然后要注意点细节,就是快速幂的时候会爆int,然后就是先判断是否为素数,是素数就直接输出结果is normal,不然会超时 AC代码: #include #include #include #include #include #include #include #include

Never say never 882

Uva 10006 Carmichael Numbers 快速幂

An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without

ccsu_cherish 666
上一篇: HDU 1166 - 敌兵布阵(树状数组)
下一篇: POJ 1751 - Highways(最小生成树)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值