也是很模板的一道题,给出一些数,分割,模数固定是4个互质的。

/** @Date    : 2017-09-16 23:54:51
* @FileName: HDU 1930 CRT.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; LL exgcd(LL a, LL b, LL &x, LL &y)
{
LL d = a;
if(b == 0)
x = 1, y = 0;
else
{
d = exgcd(b, a % b, y, x);
y -= (a / b) * x;
}
return d;
} //非互质
LL crtCD(LL &rem, LL &mod, LL newRem, LL newMod)
{
LL c = newRem - rem;// c= r2 -r1
LL g = __gcd(mod, newMod);
if(c % g!=0)
return 0;
LL x, y;
exgcd(mod, newMod, x, y);
LL t = newMod / g;// b/d
LL minx = (c / g * x % t + t) % t;//x = x' * (c/g) mod (b/d)
rem = minx * mod + rem;// newrem = mod * x + rem,
mod = mod / g * newMod; //newmod = lcm(mod, newMod)
return 1;
} LL CRT(LL n, LL rem[], LL mod[])
{
LL M = 1,x,y;
for(int i = 0; i < n; i++)
M *= mod[i];
LL res = 0;
for(int i = 0; i < n; i++)
{
LL t = M / mod[i];
exgcd(t, mod[i], x, y);
res = (res + t * rem[i] * x) % M;
} return (res % M + M) % M;
} int main()
{
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
LL mod[5];
LL rem[5];
for(int i = 0; i < 4; i++) scanf("%lld", mod + i);
for(int i = 0; i < n; i++)
{
LL x;
scanf("%lld", &x);
rem[0] = x / 1000000;
rem[1] = x / 10000 % 100;
rem[2] = x / 100 % 100;
rem[3] = x % 100;
/*cout << endl;
for(int j = 0; j < 4; j++)
cout << rem[j] << " ";
cout << endl;*/
LL nre = CRT(4, rem, mod);
LL a = nre / 10000;
LL b = nre / 100 % 100;
LL c = nre % 100;
//printf("%d %d %d~\n",a, b, c);
//cout << nre << " ";
if(i == n - 1)
{
printf("%c", a==27?' ':(a+'A'-1));
if(b != 27)
printf("%c", (b+'A'-1));
if(c != 27)
printf("%c", (c+'A'-1));
}
else
printf("%c%c%c", a==27?' ':(a+'A'-1), b==27?' ':(b+'A'-1), c==27?' ':(c+'A'-1));
}
printf("\n");
}
return 0;
}

HDU 1930 CRT的更多相关文章

  1. HDU 1573 CRT

    CRT模板题 /** @Date : 2017-09-15 13:52:21 * @FileName: HDU 1573 CRT EXGCD.cpp * @Platform: Windows * @A ...

  2. BZOJ 2976: [Poi2002]出圈游戏 HDU 5668 CRT

    2976: [Poi2002]出圈游戏 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2976 Description Input 中第一 ...

  3. 一些关于中国剩余定理的数论题(POJ 2891/HDU 3579/HDU 1573/HDU 1930)

    2891 -- Strange Way to Express Integers import java.math.BigInteger; import java.util.Scanner; publi ...

  4. HDU 5446 CRT+Lucas+快速乘

    Unknown Treasure Problem Description On the way to the next secret treasure hiding place, the mathem ...

  5. [SinGuLaRiTy] 数论题目复习

    [SinGuLaRiTy-1020] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [CQBZOJ 1464] Hankson 题目描述 H ...

  6. HDU 5768 Lucky7(CRT+容斥原理)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5768 [题目大意] 求出一个区间内7的倍数中,对于每个ai取模不等于bi的数的个数. [题解] 首 ...

  7. HDU 5446 Unknown Treasure(Lucas定理+CRT)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5446 [题目大意] 给出一个合数M的每一个质因子,同时给出n,m,求C(n,m)%M. [题解] ...

  8. hdu 5446 lucas+crt+按位乘

    http://acm.hdu.edu.cn/showproblem.php?pid=5446 题意:题目意思很简单,要你求C(n,m)mod p的值 p=p1*p2*...pn; 题解:对于C(n,m ...

  9. hdu 5446 Unknown Treasure lucas和CRT

    Unknown Treasure Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

随机推荐

  1. Alpha事后诸葛(团队)

    [设想和目标] Q1:我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? "小葵日记"是为了解决18-30岁年轻用户在记录生活时希望得到一美体验友好 ...

  2. 学生导师互选系统(php代码规范)

    学生导师互选系统(php代码规范) php编码规范 组名:一不小心就火了 负责项目:学生导师互选系统(安卓端) 编写目的 为了更好的提高团队的的合作效率,保证开发的有效性和合理性,并可最大程度的提高程 ...

  3. android studio 运行太慢了

    Android Studio每次升级/安装 Android Studio 之后最好都修改一下这个参数:到 Android Studio 安装目录,找到 bin/studio(64?).vmoption ...

  4. C++解析-外传篇(1):异常处理深度解析

    0.目录 1.异常的最终处理 2.结束函数terminate() 3.小结 1.异常的最终处理 问题: 如果在main函数中抛出异常会发生什么? 如果异常不处理,最后会传到哪里? 下面的代码的输出什么 ...

  5. 【BZOJ2432】【NOI2011】兔农(数论,矩阵快速幂)

    [BZOJ2432][NOI2011]兔农(数论,矩阵快速幂) 题面 BZOJ 题解 这题\(75\)分就是送的,我什么都不想写. 先手玩一下,发现每次每次出现\(mod\ K=1\)的数之后 把它减 ...

  6. nginx服务器去掉url中的index.php 和 配置path_info

    隐藏index.php server { listen 80; server_name yourdomain.com; root /home/yourdomain/www/; index index. ...

  7. DotNet,PHP,Java的数据库连接代码大全(带演示代码)

    C#数据库连接字符串 Web.config文件 <connectionStrings> <!--SQLServer数据库连接--> <add name="con ...

  8. 常用Transformation算子

    map 产生的键值对是tupple,      split分隔出来的是数组 一.常用Transformation算子 (map  .flatMap .filter .groupByKey .reduc ...

  9. bzoj3007: 拯救小云公主(二分+并查集)

    挺水的题...好多题解说是对偶图,其实感觉不能算严格意义上的对偶图吧QAQ 先二分答案r,然后以boss为中心半径为r的圆不能走,求能否从左下走到右上. 不能从左下走到右上,说明这堆圆把图隔开了,于是 ...

  10. LibreOJ #539. 「LibreOJ NOIP Round #1」旅游路线(倍增+二分)

    哎一开始看错题了啊T T...最近状态一直不对...最近很多傻逼题都不会写了T T 考虑距离较大肯定不能塞进状态...钱数<=n^2能够承受, 油量再塞就不行了...显然可以预处理出点i到j走c ...