#include#include#define ll long longll mod;bool Judge(int x){ for(int i=2;i0) { if(n&1) { ans*=ret; ans%=mod; } ret=(ret*ret)%mod; n>>=1; } return ans;}int main(){ int p,a; while(scanf("%d %d",&p,&a)!=EOF) { if(p==0...            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2013-09-26 16:21:00
                            
                                105阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            HPU专题训练(-1)GCD&&素筛&&快速幂_____K - Pseudoprime numbers题目来源http://poj.org/problem?id=3641第一次做的时候用的是int 没有用long long 范围比较小,出错了而且英文题目,还扯了费马小定理,百度了一下,但是也没用到写两个函数就行了,快速幂,素数判断/*...            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2022-10-18 16:46:41
                            
                                35阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            Pseudoprime numbersTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 4864Accepted: 1872DescriptionFermat'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 ve            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2021-07-29 16:17:46
                            
                                118阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            ed: 5367					DescriptionFermat's theorem states that for a...            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-02-07 12:13:36
                            
                                69阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            题 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 su            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2021-07-22 14:02:31
                            
                                137阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            #include <iostream> //二分using namespace std;__int64 p;bool prime(__int64 n){ for(__int64 i=2;i*i<=n;++i) if(n%i==0) return false; return true;}__int64 query(__int64 a,__int64 n){ if(n==1) return a; __int64 q=query(a,n/2),t=(q*q)%p; if(n%2==0) return t; else return (t*a)%p;}int main(){ __int            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2011-07-22 20:19:00
                            
                                27阅读
                            
                                                                                    
                                2评论
                            
                                                 
                 
                
                             
         
            
            
            
            #include<iostream> #include<stdio.h>#include<cmath>using namespace std;int is_prime(int x){ int m=floor(sqrt((double)x)+0.5); for(int i=2;i<=m;++i) if(x%i==0) return 0; return 1;}int power(int a,int b,int m) //快速幂取模计算 (a^b)%m{ if(a==0) return 0; else if(...            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2011-07-05 02:00:00
                            
                                26阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            【解题思路】这是一道不错的数论题目,可以学到很多东西,比如说将指数很大的数进行二进制处理,还有就是判断素数和伪素数。最有用的知识点是:1、如果p是奇数,则有(a.^p)mod(m)==((a%m)*(a.^(p-1)%m)%m成立;2、如果p是偶数,则有a.^p==a.^(p/2)*a.^(p/2)。也许可以说这两个结论人人都知道,但用起来就不是那么一回事了。#            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2022-08-05 15:48:11
                            
                                27阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            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 >            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2021-08-31 10:43:34
                            
                                30阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            题意:a的p次方p取模等于a,且p不是素数,就输出yes;#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#define ll long longusing namespace std;ll powermod(ll a            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2022-10-19 16:13:14
                            
                                22阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            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 &g            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2021-08-31 10:43:33
                            
                                51阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            DescriptionFermat'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 ...            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2015-11-09 20:41:00
                            
                                34阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            Fermat's theorem states             
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-05-18 14:19:07
                            
                                25阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            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 ...            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-05-09 10:03:19
                            
                                57阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            题目链接:http://poj.org/problem?id=3641 题目大意:给定a,p,判断一个数是不是伪素数(伪素数是指p---p满足a^p = a (mod p)但p本身不是素数),2>= 1; } return ret; } POJ 3641代码:#i...            
                
                    
                        
                                                            
                                                                        
                                                                                        转载
                                                                                    
                            2013-01-12 21:24:00
                            
                                24阅读
                            
                                                                                    
                                2评论
                            
                                                 
                 
                
                             
         
            
            
            
            快速幂:快速幂就是所求的幂次方过大,导致代码所用的时间超限。如:求2^3,3的二进制是11,(n&1)判断次方数的二进制是否为1,n>>1,向右进位1:代码:k=1,t=n;while(n)	{		if(n&1)//判断n的最后一位二进制不为0		{			k=k*m;		}		n=n>>1;		m=m*m;	}题目描述:Ferm...            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-02-14 16:21:18
                            
                                80阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld
 & %llu
Submit Status
Description
Fermat's theorem states that for any prime number p and for any integer a > 1, a            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2022-08-24 11:39:10
                            
                                30阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            http://poj.org/problem?id=3641注意计算前先 a%=p 一下。/*16ms,384KB*/#includelong long qmod(long long a, long long n, long long b){	long long ans = 1;	while (n)	{		if (n & 1)		{			ans = (ans             
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2023-04-12 03:25:50
                            
                                116阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            DescriptionFermat'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            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2022-05-27 17:11:05
                            
                                44阅读
                            
                                                                             
                 
                
                             
         
            
            
            
            题目大意:费马            
                
                    
                        
                                                            
                                                                        
                                                                                        原创
                                                                                    
                            2014-09-23 06:51:17
                            
                                45阅读