Codeforces Round #489 (Div. 2) B、C
1 second
256 megabytes
standard input
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.
The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).
In the only line print the only integer — the answer for the problem.
1 2 1 2
2
1 12 1 12
4
50 100 3 30
0
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;
}
1 second
256 megabytes
standard input
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.
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.
In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7.
2 0
4
2 1
7
3 2
21
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的更多相关文章
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- 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 ...
- 【伪暴力+智商剪枝】Codeforces Round #489 (Div. 2) D
失踪人口突然回归……orz.题解还是有必要写的,虽然估计只有自己(?自己也不一定看得懂)看得懂. 题目链接:http://codeforces.com/contest/992/problem/D 题目 ...
- 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时,此路不通.路 ...
- Codeforces Round #604 (Div. 2) D、E、F题解
Beautiful Sequence Beautiful Mirrors Beautiful Bracket Sequence (easy version) Beautiful Sequence \[ ...
- Codeforces Round #674 (Div. 3) C、D 题解
C.Increase and Copy #枚举 题目链接 题意 最初你有仅包含一个数字\(1\)的数组\(a\),一次操作中可对该数组进行两类操作: 从数组中选择一个元素,将该元素\(+1\): 从数 ...
- Codeforces Round #677 (Div. 3) E、G题解
E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...
- Codeforces Round #667 (Div. 3) B、C、D、E 题解
抱歉B.C题咕了这么久 B. Minimum Product #枚举 #贪心 题目链接 题意 给定四个整数\(a, b, x, y\),其中\(a\geq x, b\geq y\),你可以执行不超过\ ...
- Codeforces Round #660 (Div. 2) A、B、C题解
A. Captain Flint and Crew Recruitment #构造 题目链接 题意 定义一类正整数,能够被\(p*q\)表示,其中\(p.q(1<p<q)\)均为素数,称之 ...
随机推荐
- React.js 基本环境安装
安装 React.js React.js 单独使用基本上是不可能的事情.不要指望着类似于 jQuery 下载放到 <head /> 标签就开始使用.使用 React.js 不管在开发阶段生 ...
- 设置电脑IP
1.首先在Win7桌面上找到“网络”入口,如下图: 进入Win7网络 2.进入网络之后我们再点击顶部的“网络共享中心”,如下图: 进入Win7网络共享中心 3.进入Win7网络共享中心之后,我 ...
- YOLOv3模型识别车位图片的测试报告(节选)
1,YOLOv3模型简介 YOLO能实现图像或视频中物体的快速识别.在相同的识别类别范围和识别准确率条件下,YOLO识别速度最快. 官网:https://pjreddie.com/darknet/yo ...
- IDEA安装使用
下载地址: https://www.jetbrains.com/idea/download/previous.html 这里我下载的是:2016.3.8版本的 安装: 安装成功后,需要秘钥的话,在 h ...
- Node.js——render封装
封装 挂在到res上
- jQuery之Validation表单验证插件使用
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <met ...
- 合并百度影音的离线数据 with python 2.1 bdv格式的更新
最近百度影音的离线下载文件,格式有新变化. 经过分析,是bdv格式又有新格式,从最初的bdv0001,到bdv.config 的file....,这次更新的格式是直接包含一个片段,其中还有使用guid ...
- CAD交互绘制直线(com接口)
用户可以在控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY ...
- wpf Command 携带当前窗口
Command="{Binding GoPayCommand}" CommandParameter="{Binding RelativeSource={RelativeS ...
- php基础排序算法
1.冒泡排序 $arr = array(12,34,57,42,165.4,73,51); function bubbling_sort($array) { $cou = count($array); ...