数论GCD——cf1055C
被一道数论题卡了半天
网上的题解说只要匹配l或者r就行,想了下还真是。。
能让r1和r2对其就让他们对其,不能对其就讨论一下两种情况就可以了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; ll cul(ll l1, ll r1, ll l2, ll r2, ll t) {
l1 += t;
r1 += t;
return max(0ll, min(r1, r2) - max(l1, l2) + );
} int main()
{
ll l1, r1, v1, l2, r2, v2;
while(~scanf("%lld %lld %lld %lld %lld %lld", &l1, &r1, &v1, &l2, &r2, &v2)) {
l1++, r1++, l2++, r2++;
ll d = __gcd(v1, v2);
ll l = abs(r1 - r2);
ll ans = ;
ll t1 = l / d * d;
ll t2 = t1 + d;
ans = max(ans, cul(l1, r1, l2, r2, t1));
ans = max(ans, cul(l1, r1, l2, r2, t2));
ans = max(ans, cul(l2, r2, l1, r1, t1));
ans = max(ans, cul(l2, r2, l1, r1, t2));
cout << ans << endl;
}
return ;
}
数论GCD——cf1055C的更多相关文章
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- CF1025B Weakened Common Divisor【数论/GCD/思维】
#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include ...
- HDU 1722 Cake (数论 gcd)(Java版)
Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后 ...
- 数论----gcd和lcm
gcd即最大公约数,lcm即最小公倍数. 首先给出a×b=gcd×lcm 证明:令gcd(a,b)=k,a=xk,b=yk,则a×b=x*y*k*k,而lcm=x*y*k,所以a*b=gcd*lcm. ...
- hdu 5505(数论-gcd的应用)
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- CF984 C. Finite or not?【数论/GCD】
[链接]:CF [题意]:n组样例,对于每组样例,给你三个数p q b,问你p/q在b进制下是不是一个有限小数,是的话输出Finite,否则输出Infinite. [分析]:b的过程是对q约分,那么只 ...
- [NOIP2009] $Hankson$ 的趣味题 (数论,gcd)
题目链接 Solution 此题,用到的结论都是比较浅显的,但是,我竟然没想到反过来枚举... 只有50分... 被自己蠢哭... 结论比较浅显: 1.对于两个正整数\(a\),\(b\),设 \(g ...
- HDU - 5584 LCM Walk (数论 GCD)
A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. No ...
- HDU - 5974 A Simple Math Problem (数论 GCD)
题目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least ...
随机推荐
- Area--->AreaRegistrationContext.MapRoute
文章引导 MVC路由解析---IgnoreRoute MVC路由解析---MapRoute MVC路由解析---UrlRoutingModule Area的使用 Area--->AreaRegi ...
- Spring源码由浅入深系列四 创建BeanFactory
继上一章refresh之后,上图描述了obtainFreshBeanFactory过程.
- python3没有urllib2 出现报错:语法错误
我的代码:import sklearn.datasets bug: 法错误. 我的原因:Python3运行的时候的运行了你下载的urllib2.py文件,而这个文件是不属于Python3的. 解决办法 ...
- SparkStreaming整合Flume的pull方式之启动报错解决方案
Flume配置文件: simple-agent.sources = netcat-source simple-agent.sinks = spark-sink simple-agent.channel ...
- Spring 基于xml配置方式的事务(14)
参考前面的声明式事务的例子:http://www.cnblogs.com/caoyc/p/5632198.html 我们做了相应的修改.在dao中和service中的各个类中,去掉所有注解标签.然后为 ...
- pandas中axis的含义
定义一个dataframe: >>> df a b0 1 31 2 4 现在看两种用法: 1.求行的均值 >>> df.mean(axis=1)0 2.01 3.0 ...
- JS,JQuery,获得选中的Radio值
1.HTML代码 <input type=" checked="checked" /><label for="a1">男< ...
- CSIC_716_20191113【装饰器进阶以及迭代器】
装饰器的进阶主要包含叠加装饰器和有参装饰器 叠加装饰器:在一个被装饰的对象中,添加多个装饰器. 为什么要用叠加装饰器的原因: -每一个新的功能都应该写一个新的装饰器,否则会导致,代码冗余,结构不 ...
- bzoj1568 Blue Mary
题意:P:加入一条一次函数.Q:询问x位置的最大函数值. 标程: #include<bits/stdc++.h> using namespace std; ; int q,x,n; dou ...
- drop database出现1010
> drop database glc; ERROR (HY000): Error dropping database (can't rmdir './glc/', errno: 17) Fri ...