// 20181202更新

1、最大公约数(GCD)

int gcd(int x, int y) {
    return y ? gcd(y, x % y) : x; 
}

 同时,你也可以选择使用algorithm库中的__gcd(x, y)函数。

 

2、快速幂算法

int pow(int x, int y) {
    int o = x, res = 1;
    while (y) {
        if (y & 1) (res *= o) %= MOD;
        (o *= o) %= MOD;
        y >>= 1;
    }
    return res;
}

 

3、读入优化

void getint() {
    int res = 0, char ch = getchar();
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
    return res;
}

相关文章:

  • 2021-08-25
  • 2022-03-05
  • 2021-08-26
  • 2021-06-11
  • 2021-05-21
  • 2022-01-17
  • 2022-12-23
  • 2021-04-14
猜你喜欢
  • 2021-08-18
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
相关资源
相似解决方案