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. CSS ul li a 背景图片与文字对齐

    <div class="four"> <h2>电子商务</h2> <img src="images/photo2.gif&quo ...

  2. Java用SAX解析XML

    要解析的XML文件:myClass.xml <?xml version="1.0" encoding="utf-8"?> <class> ...

  3. [BZOJ1878][SDOI2009]HH的项链 莫队

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1878 不带修改的莫队,用一个桶记录一下当前区间中每种颜色的数量就可以做到$O(1)$更新了 ...

  4. (2)《Head First HTML与CSS》学习笔记---img与基于标准的HTML5

    1.浏览器处理图像的过程: 1.服务器获取文件,显示出文本结构,以及预留默认的大小给<img>(如果该<img>有width-1值和height-1值,则根据这个值提前设好页面 ...

  5. Jvisualvm--JAVA性能分析工具

    JDK自带的JAVA性能分析工具.它已经在你的JDK bin目录里了,只要你使用的是JDK1.6 Update7之后的版本.点击一下jvisualvm.exe图标它就可以运行了. 这里是VisualV ...

  6. python学习第三次

    while循环 表示当条件成立的时候就循环适用于不知道具体循环次数,但是确定在某个条件成立的情况下就循环while语法:while 条件表达式:语句块#另一种表达方式while 条件表达式:语句块1e ...

  7. vuex相关的知识

    vue的核心是store,它可以看作是一个容器,它包含着应用中的状态state(state,mutations,actions,getters, modules).它中的存储是响应式的,当store中 ...

  8. 开放API接口

    [开放API]——知乎.博客园等开放API接口(更新ing)   Cnodejs.org: https://cnodejs.org/api/ 和风天气: http://docs.heweather.c ...

  9. java线程池 多线程搜索文件包含关键字所在的文件路径

    文件读取和操作类 import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; publi ...

  10. react-native 0.58版本打包图片问题 task ':app:mergeReleaseResources' Error: Duplicate resources

    debug没问题,在生成正式apk的时候就如下: google了一下在github上找到了解决方案: github问题指向 在node_modules/react-native/react.gradl ...