/**
*中国剩余定理
*/
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cctype>
#include<cstring>
#include<cmath>
#define LL __int64
using namespace std;
/**
*gcd(a,b)=d;则存在x,y,使d=ax+by
*extended_euclid(a,b)=ax+by
*/
LL extended_euclid(LL a,LL b,LL &x,LL &y){//扩张欧几里的算法
int d;
if(b==){
x=; y=;
return a;
}
d=extended_euclid(b,a%b,y,x);
y=y-a/b*x;
return d;
}
/**
*x=b[i](modw[i]) o<i<len
*w[i]>0,且w[]中任意两个数互质
*/
LL chinese_remainder(int b[],int w[],int len){
LL res,i,d,x,y,n,m;
res=; n=;
for(i=;i<len;i++) n*=w[i];
for(i=;i<len;i++){
m=n/w[i];
extended_euclid(w[i],m,x,y);
res=(res+y*m*b[i])%n;
}
return (n+res%n)%n;
} int main()
{
int len,b[],w[];
while(cin>>len){
for(int i=;i<len;i++){
cin>>w[i]>>b[i];
}
cout<<chinese_remainder(b,w,len)<<endl; }
return ;
}

51nod1079中国剩余定理的更多相关文章

  1. 51nod--1079 中国剩余定理

    题目: 1079 中国剩余定理 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 一个正整数K,给出K Mod 一些质数的结果,求符合条件的最小的K.例如,K ...

  2. 《孙子算经》之"物不知数"题:中国剩余定理

    1.<孙子算经>之"物不知数"题 今有物不知其数,三三数之剩二,五五数之剩七,七七数之剩二,问物几何? 2.中国剩余定理 定义: 设 a,b,m 都是整数.  如果 m ...

  3. POJ 1006 中国剩余定理

    #include <cstdio> int main() { // freopen("in.txt","r",stdin); ; while(sca ...

  4. [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=12083 这道题还是挺耐想的(至少对我来说是这样).开始时我只会60 ...

  5. poj1006中国剩余定理

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103506   Accepted: 31995 Des ...

  6. (伪)再扩展中国剩余定理(洛谷P4774 [NOI2018]屠龙勇士)(中国剩余定理,扩展欧几里德,multiset)

    前言 我们熟知的中国剩余定理,在使用条件上其实是很苛刻的,要求模线性方程组\(x\equiv c(\mod m)\)的模数两两互质. 于是就有了扩展中国剩余定理,其实现方法大概是通过扩展欧几里德把两个 ...

  7. 洛谷P2480 [SDOI2010]古代猪文(费马小定理,卢卡斯定理,中国剩余定理,线性筛)

    洛谷题目传送门 蒟蒻惊叹于一道小小的数论题竟能涉及这么多知识点!不过,掌握了这些知识点,拿下这道题也并非难事. 题意一行就能写下来: 给定\(N,G\),求\(G^{\sum \limits _{d| ...

  8. 洛谷P3868 [TJOI2009]猜数字(中国剩余定理,扩展欧几里德)

    洛谷题目传送门 90分WA第二个点的看过来! 简要介绍一下中国剩余定理 中国剩余定理,就是用来求解这样的问题: 假定以下出现数都是自然数,对于一个线性同余方程组(其中\(\forall i,j\in[ ...

  9. POJ2891 Strange Way to Express Integers 扩展欧几里德 中国剩余定理

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ2891 题意概括 给出k个同余方程组:x mod ai = ri.求x的最小正值.如果不存在这样的x, ...

随机推荐

  1. [React Fundamentals] Introduction to Properties

    This lesson will teach you the basics of setting properties in your React components. class App exte ...

  2. [React Native] Using the Image component and reusable styles

    Let's take a look at the basics of using React Native's Image component, as well as adding some reus ...

  3. android 带表头,左右两个联动的ListView

    package com.rytong.mylist; import java.util.ArrayList; import java.util.HashMap; import java.util.Li ...

  4. Lazy Load 图片延迟加载(转)

    jQuery Lazy Load 图片延迟加载来源 基于 jQuery 的图片延迟加载插件,在用户滚动页面到图片之后才进行加载. 对于有较多的图片的网页,使用图片延迟加载,能有效的提高页面加载速度. ...

  5. 封装的分页jq

    (function ($) { $.fn.page = function (options) { var defaults = { divid: "pagediv", count: ...

  6. svn常用操作命令(不断更新中......)

      1.svn info显示本地或远程条目的信息.打印你的工作拷贝和URL的信息包括:路径.名称.URL.版本库的根.版本库的UUID.Revision.节点类型.最后修改作者.最后修改版本最后修改日 ...

  7. win7如何共享文件 图文教你设置win7文件共享

    点评:win7文件共享已成为网友们之间的热议,接下来为大家分享下如何共享文件,首先开启guest账户( 开始菜单 → 运行 → services.msc → 双击 server 服务项 ,设置启动类型 ...

  8. Asp.Net 5使用第三方容器

    这几天在学习Asp.Net 5,现在文档以及博客之类的资料实在太少了,不看源码几乎举步维艰,好在全都是开源的,看看微软的代码也获益良多. 看到DependencyInjection的代码里除了默认的容 ...

  9. android开发之路05

    一.获取res资源文件下values中内容的方式: 1.string.xml文件-------------------------------> 取值方式:getResource().getSt ...

  10. 为ListView添加头和脚

      转自:https://software.intel.com/zh-cn/blogs/2014/12/15/android-listview-addheaderview-addfooterview ...