首页 > 其他分享 >Fastmod

Fastmod

时间:2022-09-23 00:11:57浏览次数:32  
标签:Fastmod getmod FastMod ull include Mod

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <ctime>

typedef unsigned long long ull;
typedef __uint128_t L;

struct FastMod {
  ull b, m;
  FastMod() {}
  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
  ull getmod(ull a) {
    ull q = (ull)((L(m) * a) >> 64);
    ull r = a - q * b;
    return r >= b ? r - b : r;
  }
} Mod;
#define getmod Mod.getmod

int n;

signed main(void) {
  std::cin >> n;
  Mod = FastMod(114514);
  std::cout << getmod(n) << std::endl;
}

标签:Fastmod,getmod,FastMod,ull,include,Mod
From: https://www.cnblogs.com/Oier-GGG/p/16721293.html

相关文章