zoukankan      html  css  js  c++  java
  • quickly calc pow(i, n) since i in [1~n]

    #include <bits/stdc++.h>
    using namespace std;
    
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    const int mod = 1e9 + 7;
    const int maxn = 13000000 + 2;
    LL f[maxn];
    int prime[maxn];
    bool check[maxn];
    int n;
    
    int qp(int a, int b) {
      LL result = 1;
      LL base = a;
      while (b) {
        if (b & 1) {
          result *= base;
          result %= mod;
        }
        b >>= 1;
        base *= base;
        base %= mod;
      }
      return result;
    }
    
    void init_prime() {
      f[1] = 1;
      int total = 0;
      for (int i = 2; i <= n; ++i) {
        if (!check[i]) {
          prime[++total] = i;
          f[i] = qp(i, n);
        }
        for (int j = 1; j <= total; ++j) {
          if (i * prime[j] > n) break;
          check[i * prime[j]] = true;
          f[i * prime[j]] = f[prime[j]] * f[i] % mod;
          if (i % prime[j] == 0) break;
        }
      }
    }
    
    
    void work() {
      scanf("%d
    ", &n);
      init_prime();
      LL result = 0;
      for (int i = 1; i <= n; ++i) {
        result ^= f[i];
      }
      printf("%lld
    ", result);
    }
    
    
    int main(int argc, char *argv[]) {
      // freopen("data.txt", "r", stdin);
      work();
      return 0;
    }
    View Code

    https://ac.nowcoder.com/acm/contest/392/C

  • 相关阅读:
    PSR
    php类与对象
    二进制、位运算及其用处
    安装LNMP笔记
    计算机基础
    Python3编写HFS(CVE2014-6287)检测脚本
    windows和iis对应版本关系
    phpStudy8.1.0.1配置子域名多网站
    Xml外部实体注入
    xss小游戏通关-全答案
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/10520420.html
Copyright © 2011-2022 走看看