CodeChef Sereja and GCD
Sereja and GCDProblem code: SEAGCD
|
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
In this problem Sereja is interested in the number of arrays of integers, A1, A2, ..., AN, with 1 ≤ Ai ≤ M, such that the greatest common divisor of all of its elements is equal to a given integer D.
Find the sum of answers to this problem with D = L, D = L+1, ..., D = R, modulo 109+7.
Input
The first line of the input contains an integer T - the number of test cases. T tests follow, each containing a single line with the values of N, M, L, R.
Output
For each test case output the required sum, modulo 109+7.
Constraints
- 1 ≤ T ≤ 10
- 1 ≤ L ≤ R ≤ M
Subtasks
- Subtask #1: 1 ≤ N, M ≤ 10 (10 points)
- Subtask #2: 1 ≤ N, M ≤ 1000 (30 points)
- Subtask #3: 1 ≤ N, M ≤ 107 (60 points)
Example
- Input:
- 2
- 5 5 1 5
- 5 5 4 5
- Output:
- 3125
- 2
对于一个 d , 1~m中有 m/d个数是 d的倍数, 自然就是有 (m/d)^n种排列方法。
然而 , 这些排列当中,元素必须包含 d , 只要它减去那些只包含它的倍数的序列即可得出结果。
- #include <iostream>
- #include <cstdio>
- using namespace std ;
- typedef long long LL;
- const int mod = 1e9+;
- const int N = ;
- LL A[N] ;
- LL q_pow( LL a , LL b ) {
- LL res = ;
- while( b ) {
- if( b& ) res = res * a % mod ;
- a = a * a % mod ;
- b >>= ;
- }
- return res ;
- }
- int main() {
- // freopen("in.txt","r",stdin);
- int _ ; cin >> _ ;
- while( _-- ) {
- LL n , m , l , r ;
- cin >> n >> m >> l >> r ;
- for( int d = m ; d >= l ; --d ) {
- if( d == m || m/d != m/(d+) ) A[d] = q_pow( m/d , n );
- else A[d] = A[d+] ;
- }
- for( int i = m ; i >= l ; --i ) {
- for( int j = i + i ; j <= m ; j += i ) {
- A[i] =( ( A[i] - A[j] ) % mod + mod ) % mod ;
- }
- }
- LL ans = ;
- for( int i = l ; i <= r ; ++i )
- ans = ( ans + A[i] ) % mod ;
- cout << ans << endl ;
- }
- }
CodeChef Sereja and GCD的更多相关文章
- CodeChef DGCD Dynamic GCD
CodeChef题面 Time limit 210 ms Code length Limit //内存限制也不说一下,真是的-- 50000 B OS Linux Language limit C, ...
- CodeChef Sereja and Game [DP 概率 博弈论]
https://www.codechef.com/problems/SEAGM 题意: n个数(可能存在相同的数),双方轮流取数.如果在一方选取之后,所有已选取数字的GCD变为1,则此方输.问:1 若 ...
- ●CodeChef Sereja and Game
题链: https://www.codechef.com/problems/SEAGM题解: 概率dp,博弈论 详细题解:http://www.cnblogs.com/candy99/p/650434 ...
- CodeChef Sereja and LCM(矩阵快速幂)
Sereja and LCM Problem code: SEALCM Submit All Submissions All submissions for this problem ar ...
- scau 2015寒假训练
并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...
- BZOJ 5028 小z的加油站
bzoj链接 Time limit 10000 ms Memory limit 262144 kB OS Linux 感想 树上动态gcd的第二题也好了. [x] BZOJ 2257 [JSOI200 ...
- 洛谷 P4571 BZOJ 2257 [JSOI2009]瓶子和燃料
bzoj题目链接 上面hint那里是选择第2个瓶子和第3个瓶子 Time limit 10000 ms Memory limit 131072 kB OS Linux Source Jsoi2009 ...
- codechef January Challenge 2014 Sereja and Graph
题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...
- codechef Dynamic GCD [树链剖分 gcd]
Dynamic GCD 题意:一棵树,字词树链加,树链gcd 根据\(gcd(a,b)=gcd(a,a-b)\) 得到\(gcd(a_1, a_2, ..., a_i) = gcd(a_1, a_1- ...
随机推荐
- 03.LinuxCentOS系统root目录LVM磁盘扩容
根目录LVM扩容操作步骤: [root@centos7 ~]# df -lh文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/centos-root 50G 7.7G 43G 6% / ...
- RocketMQ集群部署安装
RcoketMQ:[ 1.低延时:在高压下,1毫秒内超过99.6%的反应延迟. 2.面向金融:具有跟踪和审计功能的高可用性. 3.行业可持续发展:保证了万亿级的消息容量. 4.厂商中立:一个新的开放的 ...
- NOIP2017 Day2 T1 奶酪(并查集)
题目描述 现有一块大奶酪,它的高度为 hhh ,它的长度和宽度我们可以认为是无限大的,奶酪 中间有许多 半径相同 的球形空洞.我们可以在这块奶酪中建立空间坐标系,在坐标系中, 奶酪的下表面为z=0z ...
- window环境下mysql导入sql文件时报错:ERROR: ASCII '\0' appeared in the statement
错误信息: ERROR: ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mo ...
- jmeter post请求在终端传参,并且指定请求参数文件
命令:jmeter -n -t jmeter_1.jmx -l report/report30.jtl -Jnum=3000 -e -o webresult/3000result ...
- 触发写Redo Log的条件
参见:http://www.ixora.com.au/notes/redo_write_triggers.htm http://www.eygle.com/archives/2005/02/redoa ...
- 22.Express框架——2019年12月19日
2019年12月19日14:16:36 1. express简介 1.1 介绍 Express框架是后台的Node框架,所以和jQuery.zepto.yui.bootstrap都不一个东西. Exp ...
- java基础复习(四)
---恢复内容开始--- 一.for循环的掌握 语法格式: for( 初始化语句A ; 条件判断B ; 循环后功能语句C){ //循环体D } for的执行流程: 整个for循环结构中 ...
- JS原型和原型链(3)
构造函数创建对象: function Person() { } var person = new Person(); person.name = 'Kevin'; console.log(person ...
- rocketmq架构设计
# 架构设计 1 技术架构 RocketMQ架构上主要分为四部分,如上图所示: Producer:消息发布的角色,支持分布式集群方式部署.Producer通过MQ的负载均衡模块选择相应的Broker集 ...