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- ...
随机推荐
- 【改】DOS文件格式转UNIX文件格式
windows中的文本文件的换行符是"\r\n",而linux中是"\n",dos格式文件传输到unix系统时,会在每行的结尾多一个^M,当然也有可能看不到,但 ...
- [CF] 8C Looking for Order
状压模板题 CF难度2000? 我得好好了解一下CF的难度机制了 反正CF的难度比洛谷真实就好了 Code #include<algorithm> #include<iostream ...
- tensorflow2.0 squeeze出错
用tf.keras写了自定义层,但在调用自定义层的时候总是报错,找了好久才发现问题所在,所以记下此问题. 问题代码 u=tf.squeeze(tf.expand_dims(tf.expand_dims ...
- 超大文件上传方案(B/S)
javaweb上传文件 上传文件的jsp中的部分 上传文件同样可以使用form表单向后端发请求,也可以使用 ajax向后端发请求 1.通过form表单向后端发送请求 <form id=" ...
- 禁止input输入框输入指定内容
链接: http://blog.csdn.net/xiaoya_syt/article/details/52746598
- FastDFS整合SpringBoot(五)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- MS4W安装教程
简介 欢迎使用MS4W,这是由Gateway Geomatics开发的快速简便的安装程序,用于为Windows及其附带应用程序(如Geomoose.MapBender.Openlayers等)设置Ma ...
- bootstrap 前端框架学习笔记
下面是一个基于 bootstrap 前端架构的最最基本的模板: (这里添加慕课网的学习笔记.) 1.认识一下 bootstrap 带来的优雅效果: 代码: <!DOCTYPE html> ...
- Android 一键分享功能简单实现
import java.io.File;import java.util.ArrayList;import java.util.List; import android.content.Context ...
- Matplotlib系列(四)--plt.bar与plt.barh条形图
(一)竖条条形图 参数说明 参数 说明 类型 x x坐标 int,float height 条形的高度 int,float width 线条的宽度 0~1,默认是0.8 botton 条形的起始位置 ...