NOIP 考前 数论复习
POJ 2891
x=r1 (mod a1)
x=r2 (mod a2)
x=a1*x+r1,x=a2*y+r2;
a1*x-a2*y=r2-r1;
用Extend_Gcd求出m1*x+m2*y=d; d=Gcd(x,y);
那么就可以解出原来的x=(x*(r2-r1)/d)
那么代入原式r1=a1*x+r1 新的a1=lcm(a1,a2);
#include <cstdio>
#define LL long long
LL a1,a2,r1,r2,x,y,n;
LL Extend_Gcd(LL a,LL b,LL &x,LL &y)
{
if (b==) {x=,y=; return a;}
LL Ret=Extend_Gcd(b,a%b,x,y);
LL Tmp=x;
x=y; y=(Tmp-a/b*y);
return Ret;
}
int main()
{
// freopen("c.in","r",stdin);
while (scanf("%lld",&n)!=EOF)
{
scanf("%lld%lld",&a1,&r1); bool Ok=true;
for (LL i=;i<n;i++)
{
scanf("%lld%lld",&a2,&r2);
LL a=a1,b=a2,m=r2-r1;
LL d=Extend_Gcd(a,b,x,y);
if (m%d) Ok=false;
x=(((x*m/d))%(b/d)+(b/d))%(b/d);
r1=x*a1+r1;
a1=(a1*a2)/d;
}
if (Ok) printf("%lld\n",r1); else puts("-1");
}
return ;
}
POJ 2891
POJ 2407 欧拉函数
#include <cstdio>
int n;
int main()
{
while (scanf("%d",&n)!=EOF)
{
if (n==) break;
int Ans=; int Tmp=n;
for (int i=;i*i<=Tmp;i++)
if (n%i==)
{
Ans=Ans*(i-);
n=n/i;
while (n%i==) Ans=Ans*i,n=n/i;
}
if (n>) Ans=Ans*(n-);
printf("%d\n",Ans);
}
return ;
}
POJ 2407
NOIP 考前 数论复习的更多相关文章
- NOIP 考前 队列复习
BZOJ 1127 #include <cstdio> #include <cstring> #include <iostream> #include <al ...
- NOIP 考前 数据结构复习
BZOJ 1455 左偏树即可 #include <cstdio> #define LL long long ; struct Info{LL l,r,v,Dis;}Tree[Maxn]; ...
- NOIP 考前DP 复习
POJ 2533 最长不降子序列 #include <cstdio> ; int a[Maxn],Pos[Maxn],F[Maxn],n,Ans; inline int Max(int x ...
- NOIP 考前 Tarjan复习
POJ 1236 给定一个有向图,求: 1) 至少要选几个顶点,才能做到从这些顶点出发,可以到达全部顶点 2) 至少要加多少条边,才能使得从任何一个顶点出发,都能到达全部顶点 第一个就是缩点之后有多少 ...
- noip考前模板复习
网络流 Dinic(搭配飞行员) //Serene #include<algorithm> #include<iostream> #include<cstring> ...
- noip数论复习总结
(上不了p站我要死了,侵权度娘背锅) 勉勉强强算是把数论复习的差不多了. 总结一下吧. 其实数论的知识大部分是结合在一起的,勉强分类总结 组合数 求法 组合数的求法根据不同情况选用不同的方法 2.3都 ...
- Noip前的大抱佛脚----Noip真题复习
Noip前的大抱佛脚----Noip真题复习 Tags: Noip前的大抱佛脚 Noip2010 题目不难,但是三个半小时的话要写四道题还是需要码力,不过按照现在的实力应该不出意外可以AK的. 机器翻 ...
- NOIP考前划水
NOIP考前划水 君指先跃动の光は.私の一生不変の信仰に.唯私の超電磁砲永世生き! 要开始背配置了? 3行不谢. (setq c-default-style "awk") (glo ...
- noip级别数论?
TAT快noip了才开始去接触数论(真心不敢学..)这里做一下整理吧(都是些定义之类的东西= =) 欧几里德:gcd(a,b)=gcd(b,a%b);具体证明见百科? 扩展欧几里德: 求a*x+b*y ...
随机推荐
- Android 常用布局视图
常用包 http://square.github.io/ EventBus Scroller 滚动 拖拽 # android.support.design.widget.CollapsingToolb ...
- Deployment failure on Tomcat 6.x. Could not copy all resources to
在myeclipse总部署项目,一直有问题,提示如下的错误,经过研究在网上需求帮助,解决方案如下: Deployment failure on Tomcat 6.x. Could not copy ...
- vue的transition过渡效果
需要4个类: *-enter: 进入的开始状态, *-enter-active: 进入的结束状态, *-leave: 离开的开始状态, *-leave-active: 离开的结束状态 vue-rout ...
- Discuz中解决jquery 冲突的方法 绝对简单
将jquery.js在common.js之前载入,不然jquery的$()函数会覆盖common.js的$()函数: 然后用到jQuery的$()函数的地方都用jQuery()代替. 例如 $(doc ...
- easy ui datagrid 让某行复选框不能选中
//百度查找出来的 onLoadSuccess: function(data){//加载完毕后获取所有的checkbox遍历 if (data.rows.length > ...
- python解析robot framework的output.xml,并生成html
一.背景 Jenkins自动构建RF脚本,生成的RF特有HTML报告不能正常打开. 需求:用Python解析测试报告的xml数据,放在普通HTML文件中打开 二.output.xml数据 三.用pyh ...
- <context:component-scan>使用说明
Spring组件扫描<context:component-scan/>使用详解 在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫 ...
- opencv 基础语法
1.关于图像:显示图象 //在指定窗口显示图像cvShowImage void cvShowImage( const char* name, const CvArr* image ); name:窗口 ...
- x64内联汇编注意点
#include <windows.h> #include <stdio.h> extern "C" int MyPrintf(ULONGLONG,ULON ...
- 在heroku上部署gost代理服务端
gost ( https://github.com/ginuerzh/gost ) gost 的 websocket tunnel 功能使用 WebSocket 协议,相较 HTTP 协议能做更多事, ...