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…
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5532 Accepted: 3210 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth…
ZOJ2150 快速幂,但是用递归式的好像会栈溢出. #include<cstdio> #include<cstdlib> #include<iostream> #include<cmath> using namespace std; long long M,i; #define LL long long int _work(LL a,LL n) { LL ans=1; while(n){ if(n&1){ ans=(ans*a)%M; n--; }…
Problem Description Xinlv wrote some sequences on the paper a long time ago, they might be arithmetic or geometric sequences. The numbers are not very clear now, and only the first three numbers of each sequence are recognizable. Xinlv wants to know…
题意: 思路: 对于每个幂次方,将幂指数的二进制形式表示,从右到左移位,每次底数自乘,循环内每步取模. #include <cstdio> typedef long long LL; LL Ksm(LL a, LL b, LL p) { LL ans = 1; while(b) { if(b & 1) { ans = (ans * a) % p; } a = (a * a) % p; b >>= 1; } return ans; } int main() { LL p, a…
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…
#include <cstdio> typedef long long ll; int quick_pow(ll a,ll b,ll mod){ ll ans=; ))ans=(ans*a)%mod; return ans; } int main(){ int z,m,h,a,b,ans; for(scanf("%d",&z);z--;){ scanf(; while(h--)scanf("%d%d",&a,&b),ans=(an…
A sequence of numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4550 Accepted Submission(s): 1444 Problem Description Xinlv wrote some sequences on the paper a long time ago, they might…
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…
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5934 Accepted: 3461 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth…
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9512 Accepted: 5783 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others…
Count Numbers 时间限制: 8 Sec 内存限制: 128 MB提交: 43 解决: 19[提交] [状态] [讨论版] [命题人:admin] 题目描述 Now Alice wants to sum up all integers whose digit sum is exactly ab .However we all know the number of this kind of integers are unlimited. So she decides to sum u…
C - Lucky Numbers Crawling in process... Crawling failed Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Description The numbers of all offices in the new building of the Tax Office of IT City will have lu…
题目链接: https://projecteuler.net/problem=435 题意: The Fibonacci numbers $ {f_n, n ≥ 0}$ are defined recursively as \(f_n = f_{n-1} + f_{n-2}\) with base cases \(f_0 = 0\) and \(f_1 = 1\). Define the polynomials $ {F_n, n ≥ 0} $ as $F_n(x) =\sum_{i=0}^{n…
-->Carmichael Numbers Descriptions: 题目很长,基本没用,大致题意如下 给定一个数n,n是合数且对于任意的1 < a < n都有a的n次方模n等于a,这个数就是Carmichael Number. 输出The number n is a Carmichael number. n是素数 输出 n is normal. Input 多组输入,第一行给一个n (2 < n < 65000) .n = 0 表示输入结束并不需要处理 Output 对…
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,…
题目链接: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…
题目链接:http://poj.org/problem?id=1995 解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可. #include<stdio.h> long long quick_mod(long long a,long long b,long long c) { long long ans=1; while(b) { if(b&1) { ans=ans*a%c; } b>>=1; a=a*a%c; } return ans; } int…