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)\)均为素数,称之 ...
随机推荐
- [转]ASP.net MVC 2 自定义模板来显示数据
本文转自:http://blog.163.com/liaojunbo@126/blog/static/1394892972012113104653651/ 在ASP.net MVC 2中,一个很有意思 ...
- 程序猿工具——svn
一个项目的产生,都需要团队中的开发人员互相协作.它的简单,方便深深吸引了我. svn的使用,有2部分组成--svn服务器.svn客户端.svn服务器一般团队之间只要有一个安装就可以了. 在学习安装sv ...
- 死磕 java集合之终结篇
概览 我们先来看一看java中所有集合的类关系图. 这里面的类太多了,请放大看,如果放大还看不清,请再放大看,如果还是看不清,请放弃. 我们下面主要分成五个部分来逐个击破. List List中的元素 ...
- java自动包装与解包
关于java的自动包装机制想必大家都用过吧,一般这些机制都用于在往容器中存储基本类型数据的时候,因为容器中不允许存在基本数据类型,所以就会调用自动包装机制,将基本数据类型转换为对象,将基本数据保存在对 ...
- Glide清除缓存
Glide是谷歌推荐的一款加载图片的第三方框架,对内存优化更好,更省资源,他的众多好处,我就不一一描述了,有兴趣的朋友可以百度一下,介绍的还是挺详细的. 今天主要给大家介绍一下关于怎么获取Glide的 ...
- javaEE web 系统安装时自定义初始化
通常JavaWeb项目在第一次启动时我们需要做一些初始化工作,比如:初始化一个管理员的登录账户和密码,配置缓存.定时任务等,这些操作可以通过手工修改数据库完成,但是容易出错且繁琐,而且也很麻烦.如果这 ...
- MySQL——sql注入
https://blog.csdn.net/lin_tuer/article/details/54809330 https://github.com/mysqljs/mysql#escaping-qu ...
- mysql 插入多条记录,重复值不插入
只去除主键与唯一索引的字段,字段为null时 是可以重复插入的domo: insert ignore into table_name(email,phone,user_id) values('test ...
- GA详解
转:http://blog.csdn.net/u010451580/article/details/51178225 本文是去年课题组周报中的一个专题讲解,详细讲了GA,由于是周报,所以十分详细.很适 ...
- 结对项目--黄金点游戏(邓乐&曾亮)
#include<stdio.h> #include<stdlib.h> #include<Windows.h> int result[100][1000000]; ...