HDUOJ---hello Kiki
Hello Kiki
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1717 Accepted Submission(s): 599
#include<iostream>
#include<cstdio>
#define LL _int64 //long long
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 ncase,n,i,j;
LL lcm,aa[],rr[];
bool ifhave;
// freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
scanf("%d",&ncase);
for(j=;j<=ncase;j++)
{
scanf("%d",&n);
lcm=;
ifhave=true;
for(i=;i<n;i++)
{
scanf("%I64d",&aa[i]);
lcm=lcm/gcd(lcm,aa[i])*aa[i];
}
for(i=;i<n;i++)
scanf("%I64d",&rr[i]);
for(i=;i<n;i++)
{
exgcd(aa[],aa[i]);
if((rr[i]-rr[])%q)
{
ifhave=false;
break;
}
int t=aa[i]/q;
x=(x*((rr[i]-rr[])/q)%t+t)%t;
rr[]+=x*aa[];
aa[]*=(aa[i]/q);
}
printf("Case %d: ",j);
if(!ifhave)
{
printf("-1\n");
}
else
{
if(rr[]!=)
printf("%I64d\n",rr[]);
else
printf("%I64d\n",lcm);
}
}
return ;
}
复制代码
HDUOJ---hello Kiki的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- hdu 3579 Hello Kiki (中国剩余定理)
Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2147 kiki's game(博弈)
kiki's game Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Submit S ...
- 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 ...
- 周赛-kiki's game 分类: 比赛 2015-08-02 09:24 7人阅读 评论(0) 收藏
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others) Total S ...
- HDU 2147 kiki's game (简单博弈,找规律)
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others)Total ...
- hdoj 2147 kiki's game【博弈】
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others)Total ...
- kiki's game
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: ...
- NYOJ 300 && hdu 2276 Kiki & Little Kiki 2 (矩阵高速功率)
pid=300">Kiki & Little Kiki 2 时间限制:5000 ms | 内存限制:65535 KB 难度:4 描写叙述 There are n light ...
随机推荐
- FFMpeg开发使用
1.jjmpeg下载 https://code.google.com/p/jjmpeg/downloads/list 2.ffmpeg文档地址 https://www.ffmpeg.org/ 3.安卓 ...
- cas4.0 session中返回更多的用户信息
实现思路: 新增AccoutAttributeDao类继承StubPersonAttributeDao,重写getPerson方法.实际应用中我们只需要修改getPersion方法中的内容,根据实际情 ...
- easyui datatimebox 取值和赋值
1.取值 var time = $('.easyui-datetimebox').datetimebox('getValue'); 全部代码如下: <script type="text ...
- nginx配置location总结
location匹配顺序 "="前缀指令匹配,如果匹配成功,则停止其他匹配 普通字符串指令匹配,顺序是从长到短,匹配成功的location如果使用^~,则停止其他匹配(正则匹配) ...
- 从原型模式(Prototype Pattern)到 Clone
前面提到抽象工厂的实现,这里说说抽象工厂的原型实现,与工厂方法的实现不同,原型实现有他自己的优点和缺点 原型的优点: 1. 效率:clone是native方法,比new的效率高,当使用复杂循环嵌套对象 ...
- mongodb实现远程连接
mongodb远程连接配置分为以下4步: 1. 添加管理员账户 > use admin switched to db admin > db.addUser('tank','test'); ...
- UVA 10012 How Big Is It?(暴力枚举)
How Big Is It? Ian's going to California, and he has to pack his things, including his collection ...
- Maximal Rectangle leetcode java
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones ...
- Logistic Regression的几个变种
原文:http://blog.xlvector.net/2014-02/different-logistic-regression/ 最近几年广告系统成为很多公司的重要系统之一,定向广告技术是广告系统 ...
- idea 设置代码的颜色