hdu 5478 Can you find it 2015上海网络赛 数论

题目

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5478

题目来源:2015上海网络赛第三题

简要题意:字典升序输出满足 ak1n+b1+bk2nk2+10modC a,b 组合

数据范围: 1C2×105;1k1,k2,b11091a,b<C

题解

一开始猜左右的余数都是不变的,然后WA了。

然后之后是猜 1,2 都成立就成立,然后就A了。

其实根本不知道为什么来的,但是就是过了。

实现

先把所有对 1 的结果映射到两个数组的ZC然后对 a 去找b中的补。

然后内部直接两个for循环去判断 2 <script type="math/tex" id="MathJax-Element-502">2</script>的时候是否满足方程。

对所有结果排序然后输出即可。

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
const int N = 2E5+5;
vector<int> a[N];
vector<int> b[N];
vector<PII> res;
int c, k1, b1, k2, cas = 1;

LL getA(int x, int n) {
    return powmod(x, 1LL*k1*n+b1, c);
}
LL getB(int x, int n) {
    return powmod(x, 1LL*k2*n-k2+1, c);
}
int main()
{
    while (scanf("%d%d%d%d", &c, &k1, &b1, &k2) == 4) {
        for (int i = 1; i < c; i++) {
            a[getA(i, 1)].pb(i);
        }
        for (int i = 1; i < c; i++) {
            b[getB(i, 1)].pb(i);
        }
        printf("Case #%d:\n", cas++);
        int op, lena, lenb;
        for (int i = 0; i < c; i++) {
            op = c-i;
            lena = a[i].size(), lenb = b[op].size();
            if (lena == 0 || lenb == 0) continue;
            for (int j = 0; j < lena; j++) {
                for (int k = 0; k < lenb; k++) {
                    if ((getA(a[i][j], 2)+getB(b[op][k], 2)) % c) continue;
                    res.pb(mp(a[i][j], b[op][k]));
                }
            }
        }
        sort(res.begin(), res.end());
        int len = res.size();
        for (int i = 0; i < len; i++) {
            printf("%d %d\n", res[i].fi, res[i].se);
        }
        if (res.size() == 0) {
            puts("-1");
        }
        for (int i = 0; i < c; i++) {
            a[i].clear();
            b[i].clear();
        }
        res.clear();
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值