Sereja and GCD

 
Problem 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

  • 1T10
  • 1LRM

Subtasks

  • Subtask #1: 1N, M10 (10 points)
  • Subtask #2: 1N, M1000 (30 points)
  • Subtask #3: 1N, M107 (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的更多相关文章

  1. CodeChef DGCD Dynamic GCD

    CodeChef题面 Time limit 210 ms Code length Limit //内存限制也不说一下,真是的-- 50000 B OS Linux Language limit C, ...

  2. CodeChef Sereja and Game [DP 概率 博弈论]

    https://www.codechef.com/problems/SEAGM 题意: n个数(可能存在相同的数),双方轮流取数.如果在一方选取之后,所有已选取数字的GCD变为1,则此方输.问:1 若 ...

  3. ●CodeChef Sereja and Game

    题链: https://www.codechef.com/problems/SEAGM题解: 概率dp,博弈论 详细题解:http://www.cnblogs.com/candy99/p/650434 ...

  4. CodeChef Sereja and LCM(矩阵快速幂)

    Sereja and LCM   Problem code: SEALCM   Submit All Submissions   All submissions for this problem ar ...

  5. scau 2015寒假训练

    并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...

  6. BZOJ 5028 小z的加油站

    bzoj链接 Time limit 10000 ms Memory limit 262144 kB OS Linux 感想 树上动态gcd的第二题也好了. [x] BZOJ 2257 [JSOI200 ...

  7. 洛谷 P4571 BZOJ 2257 [JSOI2009]瓶子和燃料

    bzoj题目链接 上面hint那里是选择第2个瓶子和第3个瓶子 Time limit 10000 ms Memory limit 131072 kB OS Linux Source Jsoi2009 ...

  8. codechef January Challenge 2014 Sereja and Graph

    题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...

  9. 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- ...

随机推荐

  1. javaweb各种框架组合案例(七):springboot+jdbcTemplete+通用dao+restful

    一.介绍 1.springboot是spring项目的总结+整合 当我们搭smm,ssh,ssjdbc等组合框架时,各种配置不胜其烦,不仅是配置问题,在添加各种依赖时也是让人头疼,关键有些jar包之间 ...

  2. 2019ICPC网赛南京站B题 super_log(欧拉降幂

    https://nanti.jisuanke.com/t/41299 题意:让算a^(a^(a^(...))),一共b个a, (mod p)的结果. 思路:这是个幂塔函数,用欧拉降幂公式递归求解. # ...

  3. 命令行界面CLI

    1.hive   -e --执行一个或多个查询 hive -e "select * from student limit 3" 2. hive -e     > 将临时查询保 ...

  4. java并发学习--第二章 spring boot实现线程的创建

    除了之前介绍的创建线程方式外,spring boot为我们了提供一套完整的线程创建方式,其中包括了:线程.线程池.线程的监控. 一.使用spring boot提供的方法创建线程与线程池 1.首先在sp ...

  5. 修改Win7登陆界面墙纸

    修改Win7登陆界面墙纸 修改注册表.reg Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\W ...

  6. 对vue的研究

    beforeDestroy 类型:Function 详细: 实例销毁之前调用.在这一步,实例仍然完全可用. 该钩子在服务器端渲染期间不被调用. 参考:生命周期图示 destroyed 类型:Funct ...

  7. SpringBoot之Web进阶

    .. 另外包括Springboot常用技术整合  以及项目上的应用

  8. [原创] Delphi Win API函数 操作帮助文件 HtmlHelpA函数介绍

    Delphi Win API函数 操作帮助文件 HtmlHelpA函数介绍 函数原型:HWND HtmlHelpA( HWND hwndCaller, LPCSTR pszFile, UINT uCo ...

  9. 【ElasticSearch】概念

    小史是一个非科班的程序员,虽然学的是电子专业,但是通过自己的努力成功通过了面试,现在要开始迎接新生活了. 对小史面试情况感兴趣的同学可以观看面试现场系列. 随着央视诗词大会的热播,小史开始对诗词感兴趣 ...

  10. python学习笔记(七)模块

    一个python文件就是一个模块 1.标准模块 python自带的,不需要你安装的 2.第三方模块 需要安装,别人提供的,例:pip install radis 如果提示没有pip,把python下s ...