【NOIP2017提高A组模拟9.5】心灵治愈
题目
好吧,我表示比赛时完全看不懂题目
题目解释
良心的出题人为一道两三句可以讲清楚的题目,又写了一大坨恶心的解释。
容斥
其实题目就是有个数组a[1n+1],已知a[n+1]=m,1<=a[1n]<=m,求a数组的每个数的最大公因数为1的方案数。
正难则反,
用a树数组的可能总数为m^n,减去最大公因数不为1的总数。
直接求出m的质数,容斥一下就可以了。
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
const int maxlongint=2147483647;
const int mo=1e9+7;
const int N=100005;
using namespace std;
long long p[N],n,m,ans;
long long mi(long long x,long long y)
{
long long sum=1;
x%=mo;
while(y)
{
if(y&1) sum=sum*x%mo;
x=x*x%mo;
y>>=1;
}
return sum;
}
void dg(int x,long long val,long long t)
{
if(x>p[0])
{
ans=(ans+mi(m/val,n)*t+mo)%mo;
return;
}
dg(x+1,val,t);
dg(x+1,val*p[x],-t);
}
int main()
{
scanf("%lld%lld",&n,&m);
long long qm=sqrt(m),m1=m;
for(long long i=2;i<=qm;i++)
if(m1%i==0)
{
p[++p[0]]=i;
while(m1%i==0) m1/=i;
}
if(m1>1) p[++p[0]]=m1;
dg(1,1ll,1);
printf("%lld",ans);
}
【NOIP2017提高A组模拟9.5】心灵治愈的更多相关文章
- JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团
100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Got ...
- JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线
5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...
- JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器
5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...
- JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)
5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)
5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...
- 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
[NOIP2017提高A组模拟9.17]信仰是为了虚无之人 Description Input Output Sample Input 3 3 0 1 1 7 1 1 6 1 3 2 Sample O ...
- 【NOIP2017提高A组模拟9.17】猫
[NOIP2017提高A组模拟9.17]猫 题目 Description 信息组最近猫成灾了! 隔壁物理组也拿猫没办法. 信息组组长只好去请神刀手来帮他们消灭猫.信息组现在共有n 只猫(n 为正整数) ...
- 【NOIP2017提高A组模拟9.17】组合数问题
[NOIP2017提高A组模拟9.17]组合数问题 题目 Description 定义"组合数"S(n,m)代表将n 个不同的元素拆分成m 个非空集合的方案数. 举个例子,将{1,2,3}拆分成2 个 ...
- 【NOIP2017提高A组模拟9.12】Arrays and Palindrome
[NOIP2017提高A组模拟9.12]Arrays and Palindrome[SPJ] 题目 Description Input Output Sample Input 1 6 Sample O ...
随机推荐
- Leetcode之广度优先搜索(BFS)专题-994. 腐烂的橘子(Rotting Oranges)
Leetcode之广度优先搜索(BFS)专题-994. 腐烂的橘子(Rotting Oranges) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ar ...
- 《0day安全-软件漏洞分析技术》实验笔记1
Crack 小实验 工具 Dev C++(书上使用的VS) IDA_Pro_v7.0 Ollydbg LordPE 010 editor 使用IDA打开文件 找到程序分支点 空格跳转到汇编界面 得到V ...
- 【神经网络与深度学习】【C/C++】比较OpenBLAS,Intel MKL和Eigen的矩阵相乘性能
比较OpenBLAS,Intel MKL和Eigen的矩阵相乘性能 对于机器学习的很多问题来说,计算的瓶颈往往在于大规模以及频繁的矩阵运算,主要在于以下两方面: (Dense/Sparse) Matr ...
- 【神经网络与深度学习】Google Protocol Buffer介绍
简介 什么是 Google Protocol Buffer? 假如您在网上搜索,应该会得到类似这样的文字介绍: Google Protocol Buffer( 简称 Protobuf) 是 Googl ...
- 【C++】A trick I learned:put boilerplate code into constructor of a struct
I learned this trick from hitonanode's submission on AtCoder. The trick is like struct fast_ios { fa ...
- 2019中山纪念中学夏令营-Day20[JZOJ] T1旅游详解
2019中山纪念中学夏令营-Day20[JZOJ] 提高组B组 Team_B组 T1 旅游 Time Limits: 2000 ms Memory Limits: 262144 KB Descrip ...
- Jmeter的操作流程
1.1 什么是 JMeter Apache JMeter 是 Apache 组织开发的基于 Java 的压力测试工具.用于对软件做压力测试,它最初被设计用于 Web 应用测试,但后来扩展到其他测试领域 ...
- DockerFile 编译语法详解
Dockerfile是一个文本格式的配置文件,用户可以使用Dockerfile来快速创建自定义的镜像,本小结首先介绍Dockerfile典型的基本结构和它支持的众多指令,并具体讲解通过这些指令来编写定 ...
- Java8 parallelStream浅析
JAVA8中引入了lamda表达式和Stream接口.其丰富的API及强大的表达能力极大的简化代码,提升了效率,同时还通过parallelStream提供并发操作的支持,本文探讨parallelStr ...
- springboot配置文件之yml的语法学习
springboot配置文件(.yml/.yaml.properties) YAML(YAML Ain't Markup Language) YAML A Markup Language:是一个标记语 ...