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数据储存之SQLiteDatabase 简单增删改查
SQLiteDatabase 使用 SQLiteDatabase提供如下方法来打开一个文件对应的数据库: openDatabase(String path, SQLiteDatabase.Cursor ...
- 18软工实践-第八次作业(课堂实战)-项目UML设计(团队)
目录 团队信息 分工选择 课上分工 课下分工 ToDolist alpha版本要做的事情 燃尽图 UML 用例图 状态图 活动图 类图 部署图 实例图 对象图 时序图 包图 通信图 贡献分评定 课上贡 ...
- asp.netcore mvc 权限拦截
1-背景介绍 需要做一个简单权限系统,基于 角色,用户,菜单 的模式 基于IActionFilter全局拦截,在内部跳转或者浏览器跳转的时候,拦截是成功的,当通过AJAX 请求的时候,页面就不会跳转 ...
- VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树
题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...
- 周总结<3>
经过了一周的学习,我们在html以及C语言方面又有的新的知识点的学习,包括计算机导论也学会了路由器的设置. html 鼠标事件 C 二叉树的遍历代码 计算机导论 路由器的设置 Html案例: < ...
- lintcode-392-打劫房屋
392-打劫房屋 假设你是一个专业的窃贼,准备沿着一条街打劫房屋.每个房子都存放着特定金额的钱.你面临的唯一约束条件是:相邻的房子装着相互联系的防盗系统,且 当相邻的两个房子同一天被打劫时,该系统会自 ...
- Spark Shuffle之Sort Shuffle
源文件放在github,随着理解的深入,不断更新,如有谬误之处,欢迎指正.原文链接https://github.com/jacksu/utils4s/blob/master/spark-knowled ...
- alpha发布评论
飞天小女警我们自己的礼物挑选工具完整度不高,页面简陋,还有很多需要完善和改进的地方,空间比较大,但是本身能力太不足. 个人比较喜欢奋斗吧兄弟做的食物链系统.感觉是可以拿来用的工具吧. 天天向上的游戏连 ...
- Android内存泄漏第二课--------(集合中对象没清理造成的内存泄漏 )
一.我们通常把一些对象的引用加入到了集合容器(比如ArrayList)中,当我们不需要该对象时,并没有把它的引用从集合中清理掉,这样这个集合就会越来越大.如果这个集合是static的话,那情况就更严重 ...
- HttpWebRequest和HttpWebResponse的应用
创建使用类HttpHelper: public class Httpparam { public string UserAgent { get; set; } public string Accept ...