HDUOJ-----X问题
X问题
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2587 Accepted Submission(s): 817
#include<iostream>
#define LL long long
#include<cstdio>
using namespace std; LL x,y,q;
LL gcd(LL a,LL b)
{
if(b!=)
return gcd(b,a%b);
else
return a;
}
void exgcd(LL a,LL b)
{
if(b==)
x= , y= , q=a;
else
{
exgcd(b,a%b);
LL temp=x;
x=y,y=temp-a/b*y;
}
} int main()
{
int test,m,i;
int n,a[],r[];
LL lcm;
bool ifhave;
scanf("%d",&test);
while(test--)
{
scanf("%d%d",&n,&m);
lcm=;
ifhave=true;
for(i=;i<m;i++)
{
scanf("%d",a+i);
lcm=lcm/gcd(lcm,a[i])*a[i]; //求最小公倍数
}
for(i=;i<m;i++)
scanf("%d",r+i);
for(i=;i<m;i++)
{
exgcd(a[],a[i]);
if((r[i]-r[])%q)
{
ifhave=false; //不需要在判断了
break;
}
LL t=a[i]/q;
x=((x*(r[i]-r[])/q)%t+t)%t;
r[]+=a[]*x;
a[]*=(a[i]/q);
}
if(!ifhave)
{
printf("0\n");
}
else
{
LL ans=;
if(r[]<=n)
ans=+(n-r[])/lcm;
if(ans&&r[]==)
ans--;
printf("%I64d\n",ans);
}
}
return ;
}
代码复制
HDUOJ-----X问题的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- hdu-oj 1874 畅通工程续
最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...
- HDUOJ题目HTML的爬取
HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...
- hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 1286 找新朋友
http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hduoj 1285 确定比赛名次
http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...
随机推荐
- jQuery2.0应用开发:SSH框架整合jQuery2.0实战OA办公自己主动化(VSS、operamasks-UI框架)
我的qq是2059055336,对这个课程有兴趣的能够加我qq联系. 一.本课程是怎么样的一门课程(全面介绍) 1.1.课程的背景 jQuery 2.0 正式版公布.不在支持 IE 6/7/8 ...
- RHPAM 7.2安装
1.产品架构 2.安装过程 下载相应介质 JBoss EAP (jboss-eap-7.2.0.zip) 下载地址 https://developers.redhat.com/products/e ...
- ubuntu上minigui调试环境的建立
minigui一共有两个版本:商业版()和GPL版(),问了一下飞漫软件,使用商业版前期的费用是9万,有技术支持,包括5000个licenses的费用,后期10K的量的话,每个licenses要6块, ...
- wifiphisher使用介绍
1.github地址:https://github.com/sophron/wifiphisher 2.需要安装在kali linux下面 3.需要两个无线网卡 4.安装方法是使用介绍,参考githu ...
- 【BZOJ】【2219】数论之神
中国剩余定理+原根+扩展欧几里得+BSGS 题解:http://blog.csdn.net/regina8023/article/details/44863519 新技能get√: LL Get_yu ...
- TreeMap源代码深入剖析
第1部分 TreeMap介绍 A Red-Black tree based NavigableMap implementation. The map is sorted according to th ...
- iOS:UITableViewCell自定义单元格
UITableViewCell:自定义的单元格,可以在xib中创建单元格,也可以在storyBorad中创建单元格.有四种创建方式 <1>在storyBorad中创建的单元格,它是静态的单 ...
- libuv之介绍
本人是在研究linux下socket TCP/IP通讯时,用到了一些linux下的API,比如socket, connect, bind,listen, accept等等,简单写个点对点的通讯,直接用 ...
- Cesium随笔(2)加载天地图地图服务【转】
Cesium自带的图层是bing地图和esri,mapbox等图层,木有中文注记,想加载中文注记的图层?废话不说,上代码: var viewer = new Cesium.Viewer('cesium ...
- assets raw 资源 AssetManager
assets raw 目录简介 assets核心特性:不会被编译成二进制,支持子目录(可以分类,这是相对raw目录最大的好处),通过文件名访问,调用getAssets通过AssetManager访问 ...