HDU 1930 CRT
也是很模板的一道题,给出一些数,分割,模数固定是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的更多相关文章
- HDU 1573 CRT
CRT模板题 /** @Date : 2017-09-15 13:52:21 * @FileName: HDU 1573 CRT EXGCD.cpp * @Platform: Windows * @A ...
- BZOJ 2976: [Poi2002]出圈游戏 HDU 5668 CRT
2976: [Poi2002]出圈游戏 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2976 Description Input 中第一 ...
- 一些关于中国剩余定理的数论题(POJ 2891/HDU 3579/HDU 1573/HDU 1930)
2891 -- Strange Way to Express Integers import java.math.BigInteger; import java.util.Scanner; publi ...
- HDU 5446 CRT+Lucas+快速乘
Unknown Treasure Problem Description On the way to the next secret treasure hiding place, the mathem ...
- [SinGuLaRiTy] 数论题目复习
[SinGuLaRiTy-1020] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [CQBZOJ 1464] Hankson 题目描述 H ...
- HDU 5768 Lucky7(CRT+容斥原理)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5768 [题目大意] 求出一个区间内7的倍数中,对于每个ai取模不等于bi的数的个数. [题解] 首 ...
- HDU 5446 Unknown Treasure(Lucas定理+CRT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5446 [题目大意] 给出一个合数M的每一个质因子,同时给出n,m,求C(n,m)%M. [题解] ...
- 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 ...
- hdu 5446 Unknown Treasure lucas和CRT
Unknown Treasure Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
随机推荐
- Android 7.1.1 又出幺蛾子了 —— 再谈 Android 上的 Wifi 连接
在之前的博客文章中,我写了点在 Android 6 系统中连接到指定名称的 Wifi 的体验.然而,在 Android 7 中,有一些东西又变化了.另外就是在那篇文章中我说要提供代码,结果拖到这篇文章 ...
- CS小分队第二阶段冲刺站立会议(5月26日)
昨天成果:对扫雷进行了全面的优化,增加了特色皮肤,为其添加了游戏音效,并且做出了换肤的接口. 今日计划:应队友要求对抽号倒计时器进行分离,修改界面结构以便美化. 遇到问题:扫雷的界面美化比较困难,自动 ...
- UVA 11270 轮廓线
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33787 题意: 用1*2或2*1的长条把n*m方格铺满的方案数. ...
- 测试bug
模板在运行时出现了以下 1 个错误:---------------------------Controller.tt(-1,-1) : error : 获取 AppDomain 以便从主机运行转换时出 ...
- YARN中用的作业调度算法:DRF(Dominant Resource Fairness)
在Mesos和YARN中,都用到了dominant resource fairness算法(DRF),它不同于hadoop基于slot-based实现的fair scheduler和capacity ...
- 0302借软件工程触IT
没有不想学好的学生,也没有选择计算机软件专业后不想过能进军IT的行业的.就对于自己情况来说,大学选择计算机商业软件专业学习也有一年多时间了,未接触专业知识前IT是一个高大上的向往,在初学C语 ...
- vue-cli脚手架搭建
我们使用vue-cli来搭建整个项目,vue-cli就是一个脚手架,步骤很简单,输入几个命令之后就会生成整个项目,里面包括了webpack.ESLint.babel很多配置等等,省了很多事 Vue+ ...
- Delphi编程防止界面卡死的方法经验分享
Delphi编程防止界面卡死的方法经验分享! 1.循环里面防止界面卡死的方法可以使用Application.ProcessMessages: 例如下列方法: var n: Integ ...
- 通过父类定位到子类 先将父类当作一个dom
通过父类定位到子类 先将父类当作一个dom 在此基础上在定位子类
- bzoj2669-局部极小值
题意 有一个 \(n\times m\) 的矩阵,其中每个数都是 \([1,n\times m]\) 中的一个,不会重复.有一些地方的值比周围的8个位置都小(如果有的话).给出这些位置,求这样的矩阵有 ...