zoukankan      html  css  js  c++  java
  • UVALive-3722 留个坑,为什么费马小定理求逆元不对??

    #include <iostream>
    #include <cstdlib>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <fstream>
    #define inf 2147483647
    #define N 1000010
    #define p(a) putchar(a)
    #define For(i,a,b) for(long long i=a;i<=b;++i)
    
    using namespace std;
    long long x,a,n,c,t,k;
    void in(long long &x){
        long long y=1;char c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
        while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
        x*=y;
    }
    void o(long long x){
        if(x<0){p('-');x=-x;}
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    long long ksm(long long a,long long b){
        long long r=1;
        while(b>0){
            if(b&1)
                r=r*a%c;
            a=a*a%c;
            b>>=1;
        }
        return r;
    }
    
    long long gcd(long long a,long long b){
        return (a%b==0?b:gcd(b,a%b));
    }
    
    long long sum(long long a,long long b){
        if(b==1)
            return a%c;
        long long half=ksm(a,b>>1);
        long long temp=sum(a,b>>1);
        if(b%2==0)
            return (temp%c+half*temp%c)%c;
        else
            return (temp%c+half*temp%c+half*half%c*a%c)%c;
    }
    
    int main(){
        while(cin>>x>>a>>n>>c&&x){
            t=ksm(a,n);
            //if(gcd(a-1,c)==1)
            //    o(((x%c*t%c-a%c*ksm(a-1,c-2)%c*((t-1)%c+c)%c)%c+c)%c);
            //else
                o(((x%c*t%c-sum(a,n))%c+c)%c);
            p('
    ');
        }
        return 0;
    }

    https://vjudge.net/problem/UVALive-3722

  • 相关阅读:
    WinHex简介
    CTF中图片隐藏文件分离方法
    隐写术的相关解法
    JPEG文件格式
    PNG文件结构
    网络安全实验室—基础关
    实验吧—密码学(1)
    YIT-CTF—隐写术
    YIT-CTF—Web
    YIT-CTF—社工类
  • 原文地址:https://www.cnblogs.com/war1111/p/11296165.html
Copyright © 2011-2022 走看看