Codeforces 992 范围内GCD,LCM要求找一对数 衣柜裙子期望
A
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 2e5 + , MAXM = 2e5 + , N = 2e5 + ;
const int MAXQ = ;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}*/
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
map<int, int> mp;
int main()
{
int n;
read(n);
int ans = ;
mp[] = ;
for (int i = ; i <= n; i++)
{
int now;
read(now);
if (!mp[now])
{
mp[now] = ;
ans++;
}
}
cout << ans << endl;
return ;
}
B
题意:
给你L,R,A,B四个数 要你找出一对在L,R范围内的数使得他们的GCD为A,LCM为B 问你有几对
解:
假设我们找到的数是X,Y 那么X*Y肯定为LCM*GCD 因为LCM=X*Y/GCD
所以我们只要在1~sqrt(LCM*GCD)范围内枚举数即可 但是LCM*GCD的最大值是1e18 平方根下来是1e9还是不行
我们观察到X,Y的GCD是X 那么就说明X,Y都是GCD的倍数 所以我们不用++枚举 直接+X枚举即可
这样的复杂度是sqrt(LCM*GCD)/GCD=sqrt(LCM/GCD) LCM/GCD最大是1e9 可以接受
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 2e5 + , MAXM = 2e5 + , N = 2e5 + ;
const int MAXQ = ;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}*/
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
ll gcd(ll a, ll b)
{
ll t;
while (b)
{
t = b;
b = a % b;
a = t;
}
return a;
}
int main()
{
ll l, r, x, y;
cin >> l >> r >> x >> y;
ll rl = l;
ll sum = x * y;
ll ans = ;
ll a, b;
if (l % x != )
{
l = (l / x + ) * x;
}
for (ll i = l; i <= sqrt(sum) && i <= r; i += x)
{
if (sum % i == )
{
a = i, b = sum / i;
if (b >= rl && b <= r)
{
if (gcd(a, b) == x)
{
if (a == b)
{
ans++;
}
else
{
ans += ;
}
//cout << a << " " << b << endl;
}
} }
}
cout << ans << endl;
return ;
}
C
题意:
你开始有X个裙子 你有K+1次增长机会 前K次会100%的增长一倍 但是增长后有50%的机会会减少一个
给你X,K(1e18) 问你最后裙子数量的期望值是多少(mod 1e9+7)
解:
纯推公式找规律题
我们很容易知道其实在K月之后(总共有K+1月)最后可能得到的裙子数是连续的
即如果刚开始有X个裙子且K=2时 他经过K月(没经过最后特殊的那一月)后可能得到的为 4*X,4*X-1,4*X-2,4*X-3 这四种答案
所以可以得到公式经过K月后的期望值为 (2k*X+2k*X-2k+1)*2k/2/2k=(2k+1*X-2k+1)/2
这是K月后的期望值 还有最后一月要*2 所以直接*2 最后的答案即为2k+1*X-2k+1
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[][] = {{, }, {, }, {, -}, { -, }, {, }, {, -}, { -, -}, { -, }};
const int mod = 1e9 + , gakki = + + + + 1e9;
const int MAXN = 2e5 + , MAXM = 2e5 + , N = 2e5 + ;
const int MAXQ = ;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
to[++tot] = v;
nxt[tot] = Head[u];
Head[u] = tot;
}*/
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
ll Qpow(ll a, ll b)
{
ll ans = , base = a;
while (b != )
{
if (b & != )
{
ans *= base;
ans %= mod;
}
base *= base;
base %= mod;
b >>= 1LL;
}
return ans;
}
int main()
{
ll x, k;
cin >> x >> k;
if (x == )
{
cout << << endl;
return ;
}
ll ans1 = Qpow(, k + );
x %= mod;
ans1 = (ans1 * x) % mod;
ll ans2 = (Qpow(, k) - + mod) % mod;
cout << (ans1 - ans2 + mod) % mod << endl;
return ;
}
D
Codeforces 992 范围内GCD,LCM要求找一对数 衣柜裙子期望的更多相关文章
- Mathematics:GCD & LCM Inverse(POJ 2429)
根据最大公约数和最小公倍数求原来的两个数 题目大意,不翻译了,就是上面链接的意思. 具体思路就是要根据数论来,设a和b的GCD(最大公约数)和LCM(最小公倍数),则a/GCD*b/GCD=LCM/G ...
- hdu-3071 Gcd & Lcm game---质因数分解+状态压缩+线段树
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3071 题目大意: 给定一个长度为n的序列m次操作,操作的种类一共有三种 查询 L :查询一个区间的所 ...
- 数论入门2——gcd,lcm,exGCD,欧拉定理,乘法逆元,(ex)CRT,(ex)BSGS,(ex)Lucas,原根,Miller-Rabin,Pollard-Rho
数论入门2 另一种类型的数论... GCD,LCM 定义\(gcd(a,b)\)为a和b的最大公约数,\(lcm(a,b)\)为a和b的最小公倍数,则有: 将a和b分解质因数为\(a=p1^{a1}p ...
- POJ 2429 GCD & LCM Inverse (Pollard rho整数分解+dfs枚举)
题意:给出a和b的gcd和lcm,让你求a和b.按升序输出a和b.若有多组满足条件的a和b,那么输出a+b最小的.思路:lcm=a*b/gcd lcm/gcd=a/gcd*b/gcd 可知a/gc ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- 洛谷 UVA11388 GCD LCM
UVA11388 GCD LCM Description of the title PDF The GCD of two positive integers is the largest intege ...
- POJ2429 GCD & LCM Inverse pollard_rho大整数分解
Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and t ...
- [POJ 2429] GCD & LCM Inverse
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10621 Accepted: ...
- POJ 2429 GCD & LCM Inverse(Pollard_Rho+dfs)
[题目链接] http://poj.org/problem?id=2429 [题目大意] 给出最大公约数和最小公倍数,满足要求的x和y,且x+y最小 [题解] 我们发现,(x/gcd)*(y/gcd) ...
随机推荐
- ListView中用鼠标拖动各项上下移动的问题。(100分)
在OnDragDrop事件中處理:以下是delphi的例子 procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integ ...
- Pytorch-索引与切片
引言 本篇介绍Pytorch 的索引与切片 索引 1234567 In[3]: a = torch.rand(4,3,28,28)In[4]: a[0].shape # 理解上相当于取第一张图片Out ...
- centos 7安装python3及相关模块
一.python3安装 1.cd /usr/bin 2.mv python python.bak 3.https://www.python.org/ftp/python/网站选择合适的版本 4.wge ...
- Invalid Django TIME_ZONE
在linux操作系统运行,设置的时区在系统文件/usr/share/zoneinfo/中找不到会出现以下错误 raceback (most recent call last): File , in & ...
- (C#)Appium自动化测试之mobile:shell输入法
1.ADB执行Shell命令 a.如果电脑上已装Appium,那么需要在高级设置里勾选 Relaxed Security. 如图: b.cmd命令行启动appium appium --rela ...
- 如何为根分区扩容(centos7为例)
linux系统所有的文件都是存放在根分区中的,如果根分区容量即将耗尽,我们就需要给根分区扩容,我们可以使用lsblk命令来查看,系统的根分区实际是逻辑卷,所以想要扩展根分区只要将逻辑卷扩容就可以了.此 ...
- Bzoj2873 光之大陆
https://blog.csdn.net/qq_39791208/article/details/79079117 有空来研究
- 语言模型评价指标Perplexity
在信息论中,perplexity(困惑度)用来度量一个概率分布或概率模型预测样本的好坏程度.它也可以用来比较两个概率分布或概率模型.(应该是比较两者在预测样本上的优劣)低困惑度的概率分布模型或概率模型 ...
- SolidWorks学习笔记3几个草图实例
绘制五角星 创建一个正五边形的内切圆,圆心和圆点重合,注意垂直关系. 选中所有,都设置为构造线. 依次连接直线, 点击裁剪实体,划过所要删除的线段. 绘制高度对称草图 注意事项: 最上和最下的圆心要和 ...
- mysql 5.6 后热数据的加载
mysql 5.6 后热数据的加载 转自:http://blog.itpub.net/20892230/viewspace-2127469/ 故障现象:在数据库重启后,碰巧遇到业务高峰期,连接数满,导 ...