HDU 5478 Can you find it (卡常数)2015 ACM/ICPC Asia Regional Shanghai Online

【题目链接】click here~~

【题目大意】;


【思路】:一早起来突然想到只要判断1,2是否符合就可以了,那么此题就是一个暴力题了,卡常数,呀。卡常数!!

HDU 5478 Can you find it (卡常数)2015 ACM/ICPC Asia Regional Shanghai Online_第1张图片

代码:


 

/*
* Problem: HDU No.5478
* Running time: 3600MS
* Complier: G++
* Author: javaherongwei
* Create Time: 17:24 2015/9/26 星期六
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
typedef long long LL;
LL C,k1,k2,b1;
LL poww(LL a,LL b)
{
    LL res=a,ans = 1 ;
    while(b)
    {
        if(b&1) ans = (ans*res)%C ;
        b>>=1 ;
        res= (res*res)%C ;
    }
    return ans%C;
}
int main()
{
    LL tot = 1;
    while(scanf("%lld %lld %lld %lld",&C,&k1,&b1,&k2)!=EOF)
    {
        printf("Case #%d:\n",tot++);
        LL s = 0;
        for(LL i = 1; i<C; i++) ///枚举a
        {
            bool ok = true;
            LL  b = C - poww(i,k1+b1); ///求b
            if(b<=0) continue;
            for(LL n =1 ; n<=2; n++) ///筛选1,2即可
            {
                LL rr = n;
                if(((LL)poww(i,k1*rr+b1)+(LL)poww(b,k2*rr-k2+1))%C!=0)
                {
                    ok = false;
                    break;
                }
            }
            if(ok)
            {
                printf("%lld %lld\n",i,b);
                s++;
            }
        }
        if(!s) ///无解!
        {
            puts("-1");
        }
    }
    return 0;
}

你可能感兴趣的:(HDU,思维,卡常数)