模板练习

posted on 2019-10-30 19:38:34
(模板练习

拓扑排序

发糖果

e[++cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;

打成

e[cnt++].next = head[u];
e[cnt].to = v;
head[u] = cnt;

数论

洛谷P1082

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int exgcd(int a, int b, int &x, int &y)
{
    if(b == 0) {
        x = 1, y = 0;
        return a;
    }
    int ret = exgcd(b, a % b, x, y);
    int temp = x;
    x = y;
    y = temp - a / b * y;
    return ret;
}
int main()
{
    int a, b, x, y;
    cin >> a >> b;
    int ret = exgcd(a, b, x, y);
    x = (x % b + b) % b;
    cout << x;
return 0;
}

乘法逆元

上一篇:HDU 5685 Problem A


下一篇:扩展欧几里得(exgcd模板)