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 ...
随机推荐
- OBjective-C:文件管理类NSFileManager
文件管理类NSFileManager类:对文件进行创建.复制.重命名.删除等,一般不对文件内容进行操作. NSData类和NSMutableData类:相当于数据缓冲区 NSFileManager是 ...
- C语言:使用realloc函数对malloc或者calloc动态分配的内存大小进行扩展
#include<stdio.h> #include<stdlib.h> #include<time.h> typedef struct { char name[3 ...
- Combinations leetcode java
题目: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For ex ...
- http://www.cnblogs.com/snake-hand/p/3206655.html
1 public class MainActivity extends Activity { 2 3 private ListView listView; 4 private ArrayList< ...
- CentOS7.0 x86_64系统上构建php开发环境--Lamp(包含设置虚拟文件夹,加入SELinux对httpd的支持等知识)
一.安装mysql,直接用yum安装就可以,mysql在centos7.0版本号中被mariadb替代了. 命令: yum install mysql-server mysql 安装好了,选择改动my ...
- Oracle数据库信息查询
查看当前数据库 select name from V$DATABASE; select SYS_CONTEXT('USERENV','INSTANCE_NAME') from dual; 用户 sel ...
- 【死磕Java并发】-----深入分析synchronized的实现原理
记得刚刚開始学习Java的时候.一遇到多线程情况就是synchronized.相对于当时的我们来说synchronized是这么的奇妙而又强大,那个时候我们赋予它一个名字"同步". ...
- js的正则匹配 和 blur
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js&qu ...
- MVC 之 属性详解
一.System [AttributeUsage]:指定另一特性类的用法.无法继承此类. [CLSCompliant]:指示程序元素是否符合公共语言规范 (CLS).无法继承此类. [ContextS ...
- 简单概率dp-hdu-4487-Maximum Random Walk
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4487 题目大意: 开始位置在0,每一步可以向右向左或者不动,问走了n步后,路径中能到达最右的期望. ...