【杭电1905】Pseudoprime numbers

来源:互联网 发布:linux 挂载硬盘 编辑:程序博客网 时间:2024/05/17 23:39

这里写图片描述
这里写图片描述
伪素数,只要看懂题别把素数算进来算就ok

#include<stdio.h>#include<math.h>__int64 quickpow(int n,int m,int t) {    __int64 ans=1,base=n;    while(m) {        if(m&1) {            ans=ans*base%t;        }        base=base*base%t;        m>>=1;    }    return ans;}bool judge(int p) {    for(int l=2; l<=sqrt(p); l++) {        if(p%l==0)            return true;    }    return false;}int main() {    int p,a;    while(scanf("%d %d",&p,&a),p||a) {        __int64 t;        if(judge(p)) {            t=quickpow(a,p,p);            if(t==a)                printf("yes\n");            else                printf("no\n");        } else            printf("no\n");    }    return 0;}

http://acm.hdu.edu.cn/showproblem.php?pid=1905

0 0