题目意思很直接就是一道裸的解线性同余模方程组的题目

 #include <cstdio>
#include <cstring> using namespace std; #define N 15
int r[N] , m[N]; int ex_gcd(int a , int &x , int b , int &y)
{
if(b == ){
x = , y = ;
return a;
}
int ans = ex_gcd(b , x , a%b , y);
int t = x;
x = y , y = t - (a/b)*y;
return ans;
} int mod_line(int n , int &t)
{
int rr = r[] , x , y;
t = m[];
for(int i= ; i<n ; i++){
int del = r[i] - rr;
int g = ex_gcd(t , x , m[i] , y);
if(del % g != )
return -;
int Mod = m[i] / g;
x = (((x*del/g)%Mod)+Mod)%Mod; rr = rr + t*x;
t = t*m[i] / g; //求二者最小公倍数,更新模项
rr %= t;
}
return rr;
} int main()
{
// freopen("a.in" , "r" , stdin);
int T;
scanf("%d" , &T);
while(T--)
{
int n , M;
scanf("%d%d" , &n , &M);
for(int i= ; i<M ; i++)
scanf("%d" , m+i);
for(int i= ; i<M ; i++)
scanf("%d" , r+i); int t;
int r = mod_line(M , t);
if(r>n || r == -) printf("0\n");
else{
int ans = (n-r)/t + ;
if(r == ) ans--;
printf("%d\n" , ans);
}
}
return ;
}

HDU 1573 解同余模线性方程组的更多相关文章

  1. HDU 1573 CRT

    CRT模板题 /** @Date : 2017-09-15 13:52:21 * @FileName: HDU 1573 CRT EXGCD.cpp * @Platform: Windows * @A ...

  2. 中国剩余定理 hdu 1573 X问题

    HDU 1573 X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. HDU 1573 X问题 中国剩余定理

    链接:pid=1573">http://acm.hdu.edu.cn/showproblem.php? pid=1573 题意:求在小于等于N的正整数中有多少个X满足:X mod a[ ...

  4. X问题 HDU - 1573(excrt入门题)

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. hdu 1573 X问题 (非互质的中国剩余定理)

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. hdu 1573 X问题

    数论题,本想用中国剩余定理,可是取模的数之间不一定互质,用不了,看到网上有篇文章写得很好的:数论——中国剩余定理(互质与非互质),主要是采用合并方程的思想: 大致理解并参考他的代码后便去试试hdu上这 ...

  7. POJ 2891 Strange Way to Express Integers (解一元线性方程组)

    求解一元线性同余方程组: x=ri(mod ai) i=1,2,...,k 解一元线性同余方程组的一般步骤:先求出前两个的解,即:x=r1(mod a1)     1x=r2(mod a2)     ...

  8. HDU 1573 X问题 (中国剩余定理)

    题目链接 题意 : 中文题不详述. 思路 : 中国剩余定理.求中国剩余定理中解的个数.看这里看这里 #include <stdio.h> #include <iostream> ...

  9. hdu 1573 A/B (扩展欧几里得)

    Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973)= 1). Input 数据的第一行 ...

随机推荐

  1. GG_DataAccess 数据库访问层使用dapper操作

    3.5.GG_DataAccess 数据库访问层使用dapper操作 和Model实体类同理,tt模板已写好,需要的可加qq群:547765059  自己下载.

  2. 构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!

    题目传送门 /* 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 另外,最多len-1次循环 */ #include <cstdio&g ...

  3. 转 MySQL实验(三) 过程式数据库对象的使用

    转 http://blog.csdn.net/anne999/article/details/70432558

  4. [转]TFS下的源代码控制

    本文转自:http://www.cnblogs.com/ajiefj/archive/2010/04/23/1718450.html 以下主要描述了: TFS源代码控制系统的基本场景 如何把一个项目添 ...

  5. ASP.NET控件之RadioButtonList

    “RadioButtonList”控件表示一个封装了一组单选按钮控件的列表控件. 可以使用两种类型的 ASP.NET 控件将单选按钮添加到网页上:各个“RadioButton”控件或一个“RadioB ...

  6. 设置Echarts鼠标悬浮样式

    在option下 tooltip内添加以下代码: (本文在后台进行传值 也就是其中的viewstate[]) tooltip: { show: true, trigger: 'axis', //sho ...

  7. 纵横填字map版(初始数据结构)

    新数据结构设计: 定义一个map: key是横纵坐标字符串,比如“0,4” value是一个json,包含以下属性:字,横向的词(若 有的话,无的话,空串),纵向的词(若有的话,无的话,空串). 另有 ...

  8. Mysql阿里数据源配置参考

    maven pom.xml配置 <dependency> <groupId>com.alibaba</groupId> <artifactId>drui ...

  9. MAGENTO 插件

    导航放到右侧:magento-community/RicoNeitzel_VertNav 后台图片管理显示图片:magento-community/TBT_Enhancedgrid magento-c ...

  10. python学习笔记(2)——练习小程序之 " input " 隐藏陷阱

    练习小程序之 ----------" input " 隐藏陷阱 age=input('please enter your age:') if age>=18: print(' ...