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要求找一对数 衣柜裙子期望的更多相关文章

  1. Mathematics:GCD & LCM Inverse(POJ 2429)

    根据最大公约数和最小公倍数求原来的两个数 题目大意,不翻译了,就是上面链接的意思. 具体思路就是要根据数论来,设a和b的GCD(最大公约数)和LCM(最小公倍数),则a/GCD*b/GCD=LCM/G ...

  2. hdu-3071 Gcd & Lcm game---质因数分解+状态压缩+线段树

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3071 题目大意: 给定一个长度为n的序列m次操作,操作的种类一共有三种 查询 L :查询一个区间的所 ...

  3. 数论入门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 ...

  4. 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 ...

  5. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

  6. 洛谷 UVA11388 GCD LCM

    UVA11388 GCD LCM Description of the title PDF The GCD of two positive integers is the largest intege ...

  7. POJ2429 GCD & LCM Inverse pollard_rho大整数分解

    Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and t ...

  8. [POJ 2429] GCD & LCM Inverse

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10621   Accepted: ...

  9. POJ 2429 GCD & LCM Inverse(Pollard_Rho+dfs)

    [题目链接] http://poj.org/problem?id=2429 [题目大意] 给出最大公约数和最小公倍数,满足要求的x和y,且x+y最小 [题解] 我们发现,(x/gcd)*(y/gcd) ...

随机推荐

  1. 如何优雅的给TDatetimePicker控件赋值(Delphi)

    给DatetimePicker赋值时,可以通过界面设置赋值,也可以通过代码赋值. 通常,我们会给表示起始时间的dtp赋值为 00:00:00,给表示结束时间的dtp赋值为23:59:59. 代码如下: ...

  2. Spring JdbcTemplate实例

    1.常用方法 * update():执行DML语句.增.删.改语句* queryForMap():查询结果将结果集封装为map集合,将列名作为key,将值作为value 将这条记录封装为一个map集合 ...

  3. redis的坑

    1.外网无法连接redis 解决方法: 把redis.conf里的bind 127.0.0.1注释掉,不行的话把127.0.0.1修改成0.0.0.0 2.make的时候显示没有gcc 解决方法: 安 ...

  4. python爬虫播放mp3

    我不明白这里出了什么问题.每次我试图在pyglet播放声音,我得到以下错误:WAVEFormatException: AVbin is required to decode compressed me ...

  5. java安全停止线程

    Thread.stop()是一个被废弃的方法,不被推荐使用的原因是stop方法太过于暴力,强行把执行到一半的线程终止,并且会立即释放这个线程所有的锁.会破坏了线程中引用对象的一致性. 使用判断标志位的 ...

  6. cisco路由的ip路由(一)

    路由Corp配置Corp#sh run Building configuration... Current configuration : 1652 bytes ! version 12.4 no s ...

  7. 【神经网络与深度学习】ZLIB介绍

    zlib类库提供了很多种压缩和解压缩的方式,由于时间的关系我只学习一下内容,以下是我在实现web 服务器压缩数据网页中使用到一些函数和常用数据结构.常量等. zlib使用过程 压缩过程:deflate ...

  8. 修改iframe内元素的样式

      $('iframe').load(function () { var x = document.getElementsByTagName('iframe')[0]; var y = (x.cont ...

  9. IIS调试

    点击调试程序的时候默认启动TFS内置的调试服务器http://localhost:51607/,在该处填写自己在IIS上配置的站点就能进入自己的站点调试http://mr.ciwong.com

  10. flask_sqlalchemy基本设置

    from flask import Flask from flask_sqlalchemy import SQLAlchemy #区别 sqlalchemy这是第三方模块不属于flask app = ...