Hello Kiki

        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
            Total Submission(s): 4206    Accepted Submission(s): 1616

Problem Description
One day I was shopping in the supermarket. There was a cashier counting coins seriously when a little kid running and singing "门前大桥下游过一群鸭,快来快来 数一数,二四六七八". And then the cashier put the counted coins back morosely and count again...
Hello Kiki is such a lovely girl that she loves doing counting in a different way. For example, when she is counting X coins, she count them N times. Each time she divide the coins into several same sized groups and write down the group size Mi and the number of the remaining coins Ai on her note.
One day Kiki's father found her note and he wanted to know how much coins Kiki was counting.
 
Input
The first line is T indicating the number of test cases.
Each case contains N on the first line, Mi(1 <= i <= N) on the second line, and corresponding Ai(1 <= i <= N) on the third line.
All numbers in the input and output are integers.
1 <= T <= 100, 1 <= N <= 6, 1 <= Mi <= 50, 0 <= Ai < Mi
 
Output
For each case output the least positive integer X which Kiki was counting in the sample output format. If there is no solution then output -1.
 
Sample Input
2
2
14 57
5 56
5
19 54 40 24 80
11 2 36 20 76
 
Sample Output
Case 1: 341
Case 2: 5996
 
Author
digiter (Special Thanks echo)
 
Source
 
Recommend
zhouzeyong   |   We have carefully selected several similar problems for you:  3573 3574 3575 3576 3577 
 
题意:Kiki有x个硬币,用了m种方法分,每次记录基数和剩余量,他爸爸呢,想要知道他的小金库有多少钱,但不会算,让你算一下;
裸中国剩余定理,互质与不互质并行
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define N 20
using namespace std;
int n,m[N],a[N],m1;
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int exgcd(int a,int b,int &x,int &y)
{
    )
    {
        x=,y=;
        return a;
    }
    int r=exgcd(b,a%b,x,y),tmp;
    tmp=x,x=y,y=tmp-a/b*y;
    return r;
}
int crt()
{
    ],a2,m2,d,c;m1=m[];
    ;i<=n;++i)
    {
        a2=a[i],m2=m[i];
        c=a2-a1;,y=;
        d=exgcd(m1,m2,x,y);
        ;
        x=x*c/d;
        int mod=m2/d;
        x=(mod+x%mod)%mod;
        a1+=m1*x;m1*=mod;
    }
    ) a1+=m1;
    return  a1;
}
int main()
{
    ;
    t=read();
    while(t--)
    {
        n=read();
        ;i<=n;++i) m[i]=read();
        ;i<=n;++i) a[i]=read();
        printf("Case %d: %d\n",++tot,crt());
    }
    ;
}

HDU——3579 Hello Kiki的更多相关文章

  1. hdu 3579 Hello Kiki

    不互质的中国剩余定理…… 链接http://acm.hdu.edu.cn/showproblem.php?pid=3579 #include<iostream>#include<st ...

  2. hdu 3579 Hello Kiki (中国剩余定理)

    Hello Kiki Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. hdu 3579 Hello Kiki 不互质的中国剩余定理

    Hello Kiki Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  4. HDU 3579——Hello Kiki

    好久没写什么数论,同余之类的东西了. 昨天第一次用了剩余定理解题,今天上百度搜了一下hdu中国剩余定理.于是就发现了这个题目. 题目的意思很简单.就是告诉你n个m[i],和n个a[i].表示一个数对m ...

  5. hdu 3579 Hello Kiki【中国剩余定理】(模数不要求互素)(模板题)

    <题目链接> 题目大意: 给你一些模数和余数,让你求出满足这些要求的最小的数的值. 解题分析: 中国剩余定理(模数不一定互质)模板题 #include<stdio.h> usi ...

  6. HDU 3579 Hello Kiki 中国剩余定理(合并方程

    题意: 给定方程 res % 14 = 5 res % 57 = 56 求res 中国剩余定理裸题 #include<stdio.h> #include<string.h> # ...

  7. 中国剩余定理 hdu 3579

    HDU 3579 Hello Kiki Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. HDU——T 3579 Hello Kiki

    http://acm.hdu.edu.cn/showproblem.php?pid=3579 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  9. 【hdu 3579】Hello Kiki(数论--拓展欧几里德 求解同余方程组)

    题意:Kiki 有 X 个硬币,已知 N 组这样的信息:X%x=Ai , X/x=Mi (x未知).问满足这些条件的最小的硬币数,也就是最小的正整数 X. 解法:转化一下题意就是 拓展欧几里德求解同余 ...

随机推荐

  1. Vue知识点小总结1

    ES6常用语法 变量的定义 let定义变量 不会变量提升 有全局作用域和函数作用域,块级作用域{} 不能重复定义 var定义变量 会变量提升 只有全局作用域和函数作用域 能够重复定义 const定义变 ...

  2. 全面学习ORACLE Scheduler特性(8)Application抛出的Events

    4.2 Application抛出的Events 首先要说明,这里所说的Application是个代词,即可以表示ORACLE数据库之外的应用程序,也可以是ORACLE数据库中的PROCEDURE等对 ...

  3. ibatis入门教程一

    这几天研究ibatis玩,参考一篇贴子进行安装配置:蓝雪森林 选择这个帖子来跟随配置是因为这个帖子看着比较干净,但是我仍旧在配置得过程中出现了好几个问题,所以我决定在这个帖子的基础上将更多细节加上,做 ...

  4. XAMPP--Apache服务无法启动问题定位及处理

    一.问题简述: XAMPP 在使用一段时间后,Apache服务无法启动. 二.详细描述: 安装Xampp服务器套件之后,部署使用正常.一段时间未使用,再次打开时,Apache服务无法启动.错误提示如下 ...

  5. C++(Typedef声明)

    typedef 声明: 使用 typedef 为一个已有的类型取一个新的名字.下面是使用 typedef 定义一个新类型的语法: typedef type newname; 例如,下面的语句会告诉编译 ...

  6. windows多线程应用编程注意事项

    1,资源争用保护 对于文件操作.界面资源.GDI操作等一般由主线程完成的任务,要加以顺序化处理(serialization),即一个资源一次只能由一个线程访问,多个线程同时访问将导致错误. 方法一般可 ...

  7. Farseer.net轻量级开源框架 入门篇:删除数据详解

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 修改数据详解 下一篇:Farseer.net轻量级开源框架 入门篇: 查询数据详解 ...

  8. (转) 淘淘商城系列——redis-desktop-manager的使用

    http://blog.csdn.net/yerenyuan_pku/article/details/72849791 实际工作环境中,redis会安装在服务器上,我们想使用redis服务就要使用re ...

  9. JavaScipt30(第一个案例)(主要知识点:键盘事件以及transitionend)

    今天得到一个github练习项目,是30个原生js写成的小例子,麻雀虽小五脏俱全,现在记录一下第一个. 第一个是键盘按键时页面上对应的键高亮,同时播放音频,松开后不再高亮. 我自己实现了一下,然后查看 ...

  10. linux 系统 UDP 丢包问题分析思路

    转自:http://cizixs.com/2018/01/13/linux-udp-packet-drop-debug?hmsr=toutiao.io&utm_medium=toutiao.i ...