B. Nastya Studies Informatics
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.

We define a pair of integers (a, b) good, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common divisorof a and b, and LCM(a, b) denotes the least common multiple of a and b.

You are given two integers x and y. You are to find the number of good pairs of integers (a, b) such that l ≤ a, b ≤ r. Note that pairs (a, b)and (b, a) are considered different if a ≠ b.

Input

The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).

Output

In the only line print the only integer — the answer for the problem.

Examples
input
1 2 1 2
output
2
input
1 12 1 12
output
4
input
50 100 3 30
output
0
Note

In the first example there are two suitable good pairs of integers (a, b): (1, 2) and (2, 1).

In the second example there are four suitable good pairs of integers (a, b): (1, 12), (12, 1), (3, 4) and (4, 3).

In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition l ≤ a, b ≤ r.

题意  在区间[l , r]内 有多少对a,b  的最小公倍数为y(lcm)  和 最大约数为x(gcd)

解析   我们知道 a*b=y*x  所以y里面肯定还有一个因子x  我们只需要考虑 y/x 有多少对因子p,q p*q=y/x且l<=q*x,p*x<=r 且 gcd(q,p)=1

AC代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+,mod = ,inf=0x3f3f3f3f;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
ll l,r,x,y;
cin>>l>>r>>x>>y;
ll ans=;
if(y%x==)
{
y=y/x;
}
else
{
cout<<ans<<endl;
return ;
}
for(ll i=;i<=sqrt(y);i++)
{
if(y%i==)
{
ll temp=y/i;
if(temp*x>=l&&temp*x<=r&&i*x>=l&&i*x<=r&&gcd(temp,i)==)
{
if(temp==i)
ans++;
else
ans+=;
// cout<<i<<" "<<temp<<endl;
}
}
}
cout<<ans<<endl;
}
C. Nastya and a Wardrobe
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).

Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year.

Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months.

Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer.

Input

The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland.

Output

In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7.

Examples
input
2 0
output
4
input
2 1
output
7
input
3 2
output
21
Note

In the first example a year consists on only one month, so the wardrobe does not eat dresses at all.

In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.

题意  有x件裙子 有k+1个月 每过一个月裙子增长一倍 但有50%的可能会少一条不包括最后一个月 问最后的数学期望

解析  数学规律题 推一推就发现 答案是有规律的 是上一个答案的两倍-1 但是我们不能模拟 要写出规律来 所以再总结一下 发现差值是 q=(4*x-2)*2的等比数列 然后求和一下加上初始值就是答案。

教训 :取模不是随便取的 ,先算一下,要爆ll的时候再取模。

AC代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+,inf=0x3f3f3f3f;
typedef long long ll;
const int mod=1e9+;
ll poww(ll n,ll m)
{
ll ans = ;
while(m > )
{
if(m & )ans = (ans * n) % mod;
m = m >> ;
n = (n * n) % mod;
}
return ans;
}
ll sum(ll a,ll n)
{
if(n==)
return ;
if(n==)
return a;
ll t=sum(a,n/);
if(n&)
{
ll cur=poww(a,n/+)%mod;
t=(t+(t*cur)%mod)%mod;
t=(t+cur)%mod;
}
else
{
ll cur=poww(a,n/)%mod;
t=(t+(t*cur)%mod)%mod;
}
return t;
}
int main()
{
ll x,m;
cin>>x>>m;
x*=;
ll temp=x*-;
if(x==)
cout<<<<endl;
else if(m==)
cout<<x%mod<<endl;
else if(m==)
cout<<(temp+)%mod<<endl;
else
{
ll ans=(x*-)%mod;
ans=ans+((sum(,m-)+)%mod)*(temp%mod)%mod;
cout<<ans%mod<<endl;
}
}

Codeforces Round #489 (Div. 2) B、C的更多相关文章

  1. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  2. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  3. 【伪暴力+智商剪枝】Codeforces Round #489 (Div. 2) D

    失踪人口突然回归……orz.题解还是有必要写的,虽然估计只有自己(?自己也不一定看得懂)看得懂. 题目链接:http://codeforces.com/contest/992/problem/D 题目 ...

  4. Codeforces Round #482 (Div. 2) C 、 Kuro and Walking Route(dfs)979C

    题目链接:http://codeforces.com/contest/979/problem/C 大致题意 给出n个点,有n-1个边将他们链接.给出x,y,当某一路径中出现x....y时,此路不通.路 ...

  5. Codeforces Round #604 (Div. 2) D、E、F题解

    Beautiful Sequence Beautiful Mirrors Beautiful Bracket Sequence (easy version) Beautiful Sequence \[ ...

  6. Codeforces Round #674 (Div. 3) C、D 题解

    C.Increase and Copy #枚举 题目链接 题意 最初你有仅包含一个数字\(1\)的数组\(a\),一次操作中可对该数组进行两类操作: 从数组中选择一个元素,将该元素\(+1\): 从数 ...

  7. Codeforces Round #677 (Div. 3) E、G题解

    E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...

  8. Codeforces Round #667 (Div. 3) B、C、D、E 题解

    抱歉B.C题咕了这么久 B. Minimum Product #枚举 #贪心 题目链接 题意 给定四个整数\(a, b, x, y\),其中\(a\geq x, b\geq y\),你可以执行不超过\ ...

  9. Codeforces Round #660 (Div. 2) A、B、C题解

    A. Captain Flint and Crew Recruitment #构造 题目链接 题意 定义一类正整数,能够被\(p*q\)表示,其中\(p.q(1<p<q)\)均为素数,称之 ...

随机推荐

  1. Laravel环境搭建

    在有了初步认知后,当然就要开始在自己的电脑上搭建Laravel的开发环境了. 系统环境需求 PHP 5.3.7或者更高版本,如果没有系统没有安装PHP环境的,请到下面地址下载:http://cn2.p ...

  2. bootstrap datatable项目封装

    (function($) {     $.fn.formJSON = function() {         var serializeObj = {};         var array = t ...

  3. 简单工厂模式-Java篇

    简单工厂模式就是考虑如何实例化对象的问题,就是说到底要实例化谁,将来会不会增加实例化对象,比如计算器类中增加开根元素,应该考虑用一个单独的类来创造实例的过程,这就是工厂.下面将利用计算器类举例,解释简 ...

  4. CF792C Divide by Three

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <cstring> #include < ...

  5. CSS综合用法

    div 居中 {position: absolute; top: 50%; left: 50%; margin-top: -180px; margin-left: -160px;}

  6. Hadoop YARN学习之组件功能简述(3)

    Hadoop YARN学习之组件功能简述(3) 1. YARN的三大组件功能简述: ResourceManager(RM)是集群的资源的仲裁者, 它有两部分:一个可插拔的调度器和一个Applicati ...

  7. 迅为I.MX6DL开发板飞思卡尔Freescale Cortex A9 迅为-iMX6双核核心板

    核心板参数 尺寸: 51mm*61mm CPU: Freescale Cortex-A9 双核精简版 i.MX6DL,主频 1.2 GHz 内存: 1GB DDR3 存储: 8GB EMMC 存储 E ...

  8. laravel如何自定义控制器目录

    默认控制器在App\Http\Controllers目录下,如何自定义目录呢? 首先我们看一下laravel的请求周期 我们看一下服务提供者RouteServicePrivder文件中的一个函数 /* ...

  9. CREATE TABLE - 定义一个新表

    SYNOPSIS CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( { column_name data_ty ...

  10. COMMIT - 提交当前事务

    SYNOPSIS COMMIT [ WORK | TRANSACTION ] DESCRIPTION 描述 COMMIT 提交当前事务. 所有事务的更改都将为其他事务可见,而且保证当崩溃发生时的可持续 ...