zoukankan      html  css  js  c++  java
  • POJ 2115 C Looooops【数论】

    很容易看出来一个同余式,说到底是解一个线性同余方程,计算机解通常有拓展欧几里得和欧拉定理两种算法,参照去年的NOIP水题,问题是这题数据范围是2^32所以要int64 TAT

    #include<cstdio>

    #include<iostream>

    #include<string.h>

    #include<math.h>

    using namespace std;

    __int64 exgcd(__int64 a,__int64 b,__int64&x,__int64 &y)

    {

        if(b==0)

        {

           x=1;y=0;return a;

        }

       else

        {

           __int64 r=exgcd(b,a %b,y,x);

           y-=x*(a/b);

           return r;

        }

    }

    __int64 lme(__int64 a,__int64 b,__int64n)//ax=b(mod n)

    {

       __int64 x,y;

       __int64 d=exgcd(a,n,x,y);

       if(b%d!=0)return -1;

       __int64 e=x*(b/d)%n+n;

       return e%(n/d);

    }

    int main()

    {

       __int64 a,b,c,k;

       scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&k);

       while(1)

        {

           __int64 d=lme(c,b-a,1LL<<k);

           if (d==-1)

           {

               printf("FOREVER ");

           }

           else

           {

               printf("%I64d ",d);

           }

           scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&k);

           if(a==0 && b==0 && c==0 && k==0) break;

        }

       return 0;

    }

  • 相关阅读:
    SQL练习题
    数据库基础
    Java-反射与注解
    Linux基础
    pipeline的使用示例
    vagrant与vrtualbox的使用
    12.04公有,私有属性,析构函数,成员属性
    12.1面向对象编程的介绍(oop):封装,继承,多态,访问私有属性
    mysql操作之二:fetchone与获取lastrowid
    10.02经典类的bug
  • 原文地址:https://www.cnblogs.com/philippica/p/4006959.html
Copyright © 2011-2022 走看看