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 ...
随机推荐
- C++ Primer 学习笔记_72_面向对象编程 --句柄类与继承[续]
面向对象编程 --句柄类与继承[续] 三.句柄的使用 使用Sales_item对象能够更easy地编写书店应用程序.代码将不必管理Item_base对象的指针,但仍然能够获得通过Sales_item对 ...
- Android中RelativeLayout和LinearLayout性能分析
先看一些现象吧:用eclipse或者Android studio,新建一个Activity自动生成的布局文件都是RelativeLayout,或许你会认为这是IDE的默认设置问题,其实不然,这是由 a ...
- JBoss Data Grid 7.2 在OpenShift环境中的Quick Start
为了在容器环境中运行,首先需要弄清楚的是在传统环境下如何运行,所以我们从传统环境开始. 先去http://access.redhat.com下载相应介质,主要是 jboss-datagrid-7.2. ...
- UIButton使用方法汇总
//按钮初始化类方法 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];//这里创建一个圆角矩形的按钮 //按 ...
- RequireJS 参考文章
入门: http://www.cnblogs.com/snandy/archive/2012/05/22/2513652.html http://www.cnblogs.com/snandy/arch ...
- Android -- onWindowFocusChanged
Android中获取手机屏幕的高度和宽度,我们知道在onCreate方法中获取到的值都是为0的,有人说可以在onClick方法中获取值,这个也是个方法 ,但在onWindowFocusChanged方 ...
- Android -- 文件扫描
启动MediaScanner服务,扫描媒体文件,程序通过发送下面的Intent启动MediaScanner服务. 扫描指定文件 public void scanFile(Context ctx, St ...
- Spark性能优化:数据倾斜调优
前言 继<Spark性能优化:开发调优篇>和<Spark性能优化:资源调优篇>讲解了每个Spark开发人员都必须熟知的开发调优与资源调优之后,本文作为<Spark性能优化 ...
- 转: 用 Eclipse 平台进行 C/C++ 开发
http://www.ibm.com/developerworks/cn/linux/opensource/os-ecc/index.html
- 3. Layout -- 1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orient ...