• HDU 5478 Can you find it 随机化 数学


    Can you find it

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

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

    Description

    Given a prime number C(1≤C≤2×105), and three integers k1, b1, k2 (1≤k1,k2,b1≤109). Please find all pairs (a, b) which satisfied the equation ak1⋅n+b1 + bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...).

    Input

    There are multiple test cases (no more than 30). For each test, a single line contains four integers C, k1, b1, k2.

    Output

    First, please output "Case #k: ", k is the number of test case. See sample output for more detail.
    Please output all pairs (a, b) in lexicographical order. (1≤a,b<C). If there is not a pair (a, b), please output -1.

    Sample Input

    23 1 1 2

    Sample Output

    Case #1:
    1 22

    HINT

    题意

    问你有多少对数,满足a^(k1⋅n+b1) + b^(k2⋅n−k2+1) = 0 (mod C)

    题解:

    首先你要知道,对于每个a只有唯一对应的b可以满足这个式子,因为当n=1的时候,a^(k1+b1)+b = kk*C

    由于b是小于c的,所以只有一个

    所以我们可以求出b来,然后我们怎么check这个b究竟是不是呢?

    随机化10个数,然后随便check就好了

    代码:

    //qscqesze
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 100006
    #define mod 1000000007
    #define eps 1e-9
    #define e exp(1.0)
    #define PI acos(-1)
    const double EP  = 1E-10 ;
    int Num;
    //const int inf=0x7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    
    ll fMul(int m,ll n,int k)
    {
        ll cc = m;
        ll b = 1;
        while (n > 0)
        {
              if (n & 1LL)
                {
                    b = (b*cc);
                    if(b>=k)
                        b%=k;
                }
              n = n >> 1LL ;
              cc = (cc*cc)%k;
              if(cc>=k)cc%=k;
        }
        return b;
    }
    int main()
    {
        //freopen("out.txt","r",stdin);
        //freopen("out2.txt","w",stdout);
        srand(time(NULL));
        int tot = 1;
        int c ,k1 ,b1 ,k2;
        while(scanf("%d%d%d%d",&c,&k1,&b1,&k2)!=EOF)
        {
            printf("Case #%d:
    ",tot++);
            int flag1 = 0;
            for(int i=1;i<c;i++)
            {
                int j=c-fMul(i,k1*1+b1,c);
                int flag = 1;
                for(int k=1;k<=15;k++)
                {
                    ll tt = rand()%c+1;
                    ll ttt1 = k1, ttt2 = k2,ttt3 = b1;
                    if((fMul(i,ttt1*tt+ttt3,c)+fMul(j,ttt2*tt-ttt2+1LL,c))%c!=0)
                    {
                        flag = 0;
                        break;
                    }
                }
                if(flag)
                {
                    printf("%d %d
    ",i,j);
                    flag1=1;
                }
            }
            if(!flag1)
                printf("-1
    ");
        }
    }
  • 相关阅读:
    一文告诉你,为什么要研究JVM原理
    高并发中使用到的RateLimiter源码解析
    WEB应用服务架构的演变(扫盲)
    网上安全方面的涉及到的方面(详解)
    JDK安装
    JDKJRKSDK的区别
    本地同时安装oracle客户端与服务端的注意事项
    WMS不同货主的货如何管理
    LeetCode 101
    WMS一物一码、唯一码
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4841383.html
Copyright © 2020-2023  润新知