Loading

Fastmod

#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;
}
posted @ 2022-09-22 23:59  Aonynation  阅读(36)  评论(0编辑  收藏  举报