Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1, a^p == 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…
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if there exists an integer c such that a = b * c. Input Input starts with an integer T (≤ 525), denot…
题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers 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 is a. Some (but…
POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Carmichael Number 的简化版 /* * Created: 2016年03月30日 22时32分15秒 星期三 * Author: Akrusher * */ #include <cstdio> #include <cstdlib> #include <cstring&g…
Pseudoprime numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11336   Accepted: 4891 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…
Pseudoprime numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10903   Accepted: 4710 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…
HDU-1576 A/B 基础数论+解题报告 题意 求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973) (我们给定的A必能被B整除,且gcd(B,9973) = 1). 输入 数据的第一行是一个T,表示有T组数据. 每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9). 输出 对应每组数据输出(A/B)%9973. 解题思路 看到这里就能想到这个题是有关数论的了吧. 下面是对题目给的公式进行一些变形 设p=9973,令(C就是我们…
Pseudoprime numbers Descriptions 费马定理指出,对于任意的素数 p 和任意的整数 a > 1,满足 ap = a (mod p) .也就是说,a的 p 次幂除以 p 的余数等于 a .p 的某些 (但不是很多) 非素数的值,被称之为以 a 为底的伪素数,对于某个 a 具有该特性.并且,某些 Carmichael 数,对于全部的 a 来说,是以 a为底的伪素数. 给定 2 < p ≤ 1000000000 且 1 < a < p ,判断 p 是否为以 …
Pseudoprime numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7954 Accepted: 3305 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…
题目链接: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 is a. Some (but not very many) non-prime values of p, know…
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 is a. Some (but not very many) non-prime values of p, known as base-a ps…
上期为大家介绍了目前常见加密算法,相信阅读过的同学们对目前的加密算法也算是有了一个大概的了解.如果你对这些解密算法概念及特点还不是很清晰的话,昌昌非常推荐大家可以看看HTTPS的加密通信原理,因为HTTPS加密通信使用了目前主要的三种加密算法,大家可以从中体会到各种加密算法的优缺点. 一.目前常见加密算法简介 二.RSA算法介绍及数论知识介绍 三.RSA加解密过程及公式论证 二.RSA算法介绍及数论知识介绍 如果上期(目前常见加密算法简介)算是天安门前的话,那今天的内容就算是正式通过天安门进入故…
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1, a^p == 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…
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,…
ACM&OI 基础数学算法专题 一.数论基础 质数及其判法 (已完结) 质数的两种筛法 (已完结) 算数基本定理与质因数分解 (已完结) 约数与整除 (已完结) 整除分块 (已完结) 最大公约数.最小公倍数的两种求法 (已完结) 同余与剩余类 (已完结) 互质与欧拉函数 (已完结) 快速幂 (已完结) 费马小定理与威尔逊定理 (已完结) 欧拉定理及其推论.普适形式 裴属定理与拓展欧几里得算法 乘法逆元的求法 乘法逆元的线性筛法 线性同余方程 拉格朗日插值到中国剩余定理 拓展中国剩余定理 二.迪利…
 强伪素数 题目大意:利用费马定理找出强伪素数(就是本身是合数,但是满足费马定理的那些Carmichael Numbers) 很简单的一题,连费马小定理都不用要,不过就是要用暴力判断素数的方法先确定是不是素数,然后还有一个很重要的问题,那就是a和p是不互质的,不要用a^(p-1)=1(mod p)这个判据,比如4^6=4(mod 6),但是4^5=4(mod 6) #include <iostream> #include <functional> #include <algo…
题 Description Jerry is caught by Tom. He was penned up in one room with a door, which only can be opened by its code. The code is the answer of the sum of the sequence of number written on the door. The type of the sequence of number is 1^m + 2^m + 3…
题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为poj不能用srand()...之后各种WA..因为里面(a,p) ?= 1不一定互素,即这时Fermat定理的性质并不能直接用欧拉定理来判定..即 a^(p-1)%p = 1判断是错误的..作的 #include<iostream> #include<cstdio> #include&l…
Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17407    Accepted Submission(s): 7565 Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble numb…
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: #include <bits/stdc++.h> typedef long long ll; using namespace std; ; ll num[maxn]; int n,ans[maxn]…
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is…
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + n$,也就是求n^2的因子数量 /** @Date : 2017-09-08 10:45:12 * @FileName: HDU 1299 数论 分解.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link…
Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and she is better than him at it. Prime numbers are of mystical importance in Arithmancy, and Lucky Numbers even more so. Lucky Number…
A - Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4320 Description Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers". Th…
Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University , noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits o…
#include <cstring> #include <cstdio> #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define LL long long LL p,res,a; bool judge_prime(LL k) { LL i; LL u=int(sqrt(k*1.0)); ;i<=u;i++) { ) ; }…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060   这道题运用的是数学方法. 假设S=n^n.两边同时取对数,得到lgS=nlgn.即有S=10^(nlgn). 把nlgn看做一个整体,假设它是由整数加上介于0到1之间的小数相加得到的. 那么整数部分就不考虑了,就单纯的放大倍数而已.取决于小数部分. 小数部分=nlgn-(__int64)nlgn.注意是__int64.因为小数部分在0到1之间,所以10得次方得到的数必定大于等于1且小于10…
找范围内回文素数,最大到1e8,我就是要枚举回文串,再判素数,然后因为这种弱智思路死磕了很久题目. /** @Date : 2017-09-08 15:24:43 * @FileName: HDU 1431 思维 找回文素数.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ */ #include <bits/std…
定义一种数位simth数,该数的各位之和等于其所有质因子所有位数字之和,现给出n求大于n的最小该种数,n最大不超过8位,那么直接暴力就可以了. /** @Date : 2017-09-08 14:12:08 * @FileName: HDU 1333 素因子 暴力.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : $Id$ *…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2629 题意: 输入两个非负整数a.b和正整数n(0≤a,b<2^64,1≤n≤1000),你的任务是计算f(a^b)除以n的余数.其中f(0)=0,f(1)=1,且对于所有非负整数i,f(i+2)=f(i+1)+f(i). 分析: 所有计算都是对n取模的,设F(i)=f(i)…