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 ...
随机推荐
- poj 2585 Window Pains 解题报告
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2027 Accepted: 1025 Desc ...
- AS 常用插件 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- GoLang中面向对象的三大特性
有过 JAVA 语言学习经历的朋友都知道,面向对象主要包括了三个基本特征:封装.继承和多态.封装,就是指运行的数据和函数绑定在一起,JAVA 中主要是通过 super 指针来完成的:继承,就是指 cl ...
- 应用程序在状态栏展示时间(C#)
private DispatcherTimer _timer; private void SetTimeElaspInStatusBar() { try { _timer = new Dispatch ...
- Netdata Linux下性能实时监测工具
导读 本文将介绍一款非常好用的工具——Netdata,这是一款Linux性能实时监测工具,为一款开源工具,我对其英文文档进行了翻译,水平有限,有翻译错误的地方欢迎大家指出,希望本文对大家有所帮助,谢谢 ...
- BSTR
BSTR A BSTR (Basic string or binary string) is a string data type that is used by COM, Automation, a ...
- (LeetCode 21)Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- Android studio 2.0--android增量更新的那些事
用了这么久的AS 2.0预览版本号.4.7日谷歌最终公布了android studio 2.0正式版,小编当日便下载了.玩了一下.感觉第二次build编译明显快了,并且好像并没有又一次部署apk.经过 ...
- T-SQL 之 自定义函数
和存储过程很相似,用户自定义函数也是一组有序的T-SQL语句,UDF被预先优化和编译并且作为一个单元进行调用.UDF和存储过程的主要区别在于返回结果的方式. 使用UDF时可传入参数,但不可传出参数.输 ...
- DataGrid前台数据绑定技巧
(1)DataGrid控件不换行,数据显示不完全后面加"..." <%# DataBinder.Eval(Container.DataItem,? DataBinder.Ev ...