欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

51nod“省选”模测第二场 B 异或约数和(数论分块)

程序员文章站 2023-01-02 18:47:20
题意 "题目链接" Sol 这题是来搞笑的吧。。 考虑一个数的贡献是$O(\frac{N}{i})$ 直接数论分块。 cpp include define Pair pair define MP(x, y) make_pair(x, y) define fi first define se seco ......

题意

题目链接

sol

这题是来搞笑的吧。。

考虑一个数的贡献是\(o(\frac{n}{i})\)

直接数论分块。

#include<bits/stdc++.h> 
#define pair pair<int, int>
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
#define int long long 
#define ll long long 
#define ull unsigned long long 
#define fin(x) {freopen(#x".in","r",stdin);}
#define fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
const double eps = 1e-9;
template <typename a, typename b> inline bool chmin(a &a, b b){if(a > b) {a = b; return 1;} return 0;}
template <typename a, typename b> inline bool chmax(a &a, b b){if(a < b) {a = b; return 1;} return 0;}
template <typename a, typename b> inline ll add(a x, b y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename a, typename b> inline void add2(a &x, b y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename a, typename b> inline ll mul(a x, b y) {return 1ll * x * y % mod;}
template <typename a, typename b> inline void mul2(a &x, b y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename a> inline void debug(a a){cout << a << '\n';}
template <typename a> inline ll sqr(a x){return 1ll * x * x;}
template <typename a, typename b> inline ll fp(a a, b p, int md = mod) {int b = 1;while(p) {if(p & 1) b = mul(b, a);a = mul(a, a); p >>= 1;}return b;}
template <typename a> a inv(a x) {return fp(x, mod - 2);}
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n;
int s(int n) {
    ll t= n&3;
    if (t&1) return t/2ull^1;
    return t/2ull^n;
}
signed main() {
    n = read();
    int ans = 0;
    for(int i = 1, nxt; i <= n; i = nxt + 1) {
        nxt = n / (n / i); 
        if((n / i) & 1) {
            ans ^= s(nxt) ^ s(i - 1);
        }
    }
    cout << ans;    
    return 0;
}