反演一下可以得到$b_i=\sum\limits_{d=1}^i{\mu(i)(\lfloor \frac{i}{d} \rfloor})^n$

整除分块的话会T, 可以维护一个差分, 优化到$O(nlogn+klogk)$

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(i,1,n) cout<<a[i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 2e6+10;
int n, k, mu[N];
ll po[N], sum[N]; int main() {
scanf("%d%d", &n, &k);
mu[1] = 1;
REP(i,1,N-1) {
for (int j=2*i; j<=N-1; j+=i) mu[j]-=mu[i];
po[i] = qpow(i,n);
}
ll ans = 0;
REP(i,1,k) {
if (mu[i]) for (int j=i; j<=k; j+=i) {
sum[j]+=mu[i]*(po[j/i]-po[j/i-1]);
}
(sum[i]+=sum[i-1])%=P;
if (sum[i]<0) sum[i]+=P;
ans+=i^sum[i];
}
printf("%lld\n", (ans%P+P)%P);
}

Coprime Arrays CodeForces - 915G (数论水题)的更多相关文章

  1. A. Arrays(Codeforces Round #317 水题)

    A. Arrays time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  2. Codeforces数据结构(水题)小结

    最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...

  3. CodeForces 705A Hulk (水题)

    题意:输入一个 n,让你输出一行字符串. 析:很水题,只要判定奇偶性,输出就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240 ...

  4. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

  5. HDU 3215 The first place of 2^n (数论-水题)

    The first place of 2^n Problem Description LMY and YY are mathematics and number theory lovers. They ...

  6. CodeForces 705B (训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/B 题意略解: 两个人玩游戏,解数字,一个数字可以被分成两个不同或相同的数字 (3可以解成 1 2) ...

  7. codeforces hungry sequence 水题

    题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #inclu ...

  8. codeforces 377A. Puzzles 水题

    A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/33 ...

  9. CodeForces 474B Worms (水题,二分)

    题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...

随机推荐

  1. c# Database类的使用

    参考资料http://ansonlh.iteye.com/blog/1689009 搜索:c# DatabaseFactory类

  2. NLP related basic knowledge with deep learning methods

    NLP related basic knowledge with deep learning methods  2017-06-22   First things first >>> ...

  3. poi导出excel 并处理插入网络图片 范例 处理文件下载中文乱码

    package com.inborn.inshop.controller.product; import com.inborn.inshop.common.util.DateUtils;import ...

  4. 6、tcp_wrapper

    iptables的链接跟踪表最大容量为/proc/sys/net/ipv4/ip_conntrack_max,链接碰到各种状态的超时后就会从表中删除. 所以解決方法一般有两个: (1) 加大 ip_c ...

  5. Oracle spatial、openlayers、geoserver开发地理信息系统总结

    感谢开源,使用OpenLayers+Geoserver的地理信息系统开发很简单,完全可以套用开发MIS系统的经验,我这里总结为三个步骤: 1.数据准备 2.数据发布 3.数据展现 我将按照这个思路来介 ...

  6. Codeforces 786 B. Legacy

    题目链接:http://codeforces.com/contest/786/problem/B 典型线段树优化连边,线段树上的每一个点表示这个区间的所有点,然后边数就被优化为了至多${nlogn}$ ...

  7. 【BZOJ】4011: [HNOI2015]落忆枫音

    题目链接:http://blog.csdn.net/popoqqq/article/details/45194103 写代码的时候也没有很清晰....具体看这里吧 #include<iostre ...

  8. Codeforces 767D - Cartons of milk

    题目链接:http://codeforces.com/contest/767/problem/D D比C水系列. 将商店里面的牛奶按照保质期升序排序(显然优先买保质期久的)考虑二分答案,然后再将整个序 ...

  9. idea创建web聚合工程(2)

    参考文档: intelj idea 创建聚合项目(典型web项目,包括子项目util.dao.service) 使用IntelliJ IDEA创建Maven聚合工程.创建resources文件夹.ss ...

  10. format格式化函数

    注意:列表索引设置参数,‘0’是必须的.