Coprime Arrays CodeForces - 915G (数论水题)
反演一下可以得到$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 (数论水题)的更多相关文章
- A. Arrays(Codeforces Round #317 水题)
A. Arrays time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Codeforces数据结构(水题)小结
最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...
- CodeForces 705A Hulk (水题)
题意:输入一个 n,让你输出一行字符串. 析:很水题,只要判定奇偶性,输出就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240 ...
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- 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 ...
- CodeForces 705B (训练水题)
题目链接:http://codeforces.com/problemset/problem/705/B 题意略解: 两个人玩游戏,解数字,一个数字可以被分成两个不同或相同的数字 (3可以解成 1 2) ...
- codeforces hungry sequence 水题
题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #inclu ...
- codeforces 377A. Puzzles 水题
A. Puzzles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/33 ...
- CodeForces 474B Worms (水题,二分)
题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...
随机推荐
- 放棋子|2012年蓝桥杯B组题解析第七题-fishers
(13')放棋子 今有 6 x 6 的棋盘格.其中某些格子已经预先放好了棋子.现在要再放上去一些,使得:每行每列都正好有3颗棋子.我们希望推算出所有可能的放法.下面的代码就实现了这个功能. 初始数组中 ...
- 黄金连分数|2013年蓝桥杯B组题解析第四题-fishers
黄金连分数 黄金分割数0.61803... 是个无理数,这个常数十分重要,在许多工程问题中会出现.有时需要把这个数字求得很精确. 对于某些精密工程,常数的精度很重要.也许你听说过哈勃太空望远镜,它首次 ...
- hihoCoder week14 无间道之并查集
并查集的基本使用 #include <bits/stdc++.h> using namespace std; ; int n, fa[N]; int cnt, tot; map<st ...
- 将tiff文件转化为jpg文件并保存
jar包准备 jai-codec和jai-core 主要过程 private boolean parseTifFile(FileItem item) { logger.info("----- ...
- Leetcode167-Two Sum II Input array is sorted-Easy
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- 转载]SAP囚徒 - 通过销售订单领用到成本中心,FI替代
转载]SAP囚徒 - 通过销售订单领用到成本中心,FI替代 原文地址:SAP囚徒 - 通过销售订单领用到成本中心,FI替代实现不同成本中心记账科目不同作者:SAP囚徒 物品领用通常是库存管理的范畴 ...
- HTTP Status 404 - No result defined for action com.ouyang.action.GreetingAction and result success 错误解决办法
1.原来设置的包声明: <package name="myPackage" extends="struts-default"> <!-- 定义 ...
- 线程中为控件赋值Winform
this.Invoke(new MethodInvoker(() => { //TO DO })); this.Invoke(new Action(()=>{ // TO DO }));
- 返回Json格式结果
static string ReturnData(int resultCode, string resultMessage = "", string resultData = &q ...
- R语言可视化学习笔记之添加p-value和显著性标记--转载
https://www.jianshu.com/p/b7274afff14f?from=timeline #先加载包 library(ggpubr) #加载数据集ToothGrowth data(&q ...