华中农业大学第五届程序设计大赛网络同步赛-D
Problem D: GCD
Time Limit: 1 Sec Memory Limit: 1280 MB
Submit: 179 Solved: 25
[Submit][Status][Web Board]
Description
Input
The first line is an positive integer T. (
Output
In each test case, output the compute result of
Sample Input
1
1 2 3
Sample Output
1
HINT
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 100 using namespace std; int MOD; struct Matrix
{
LL a[MAXN][MAXN];
int r, c;
}; Matrix ori, res; void init()
{
memset(res.a, , sizeof(res.a));
res.r = ; res.c = ;
for(int i = ; i <= ; i++)
res.a[i][i] = ;
ori.r = ; ori.c = ;
ori.a[][] = ori.a[][] = ori.a[][] = ;
ori.a[][] = ;
} Matrix multi(Matrix x, Matrix y)
{
Matrix z;
memset(z.a, , sizeof(z.a));
z.r = x.r, z.c = y.c;
for(int i = ; i <= x.r; i++)
{
for(int k = ; k <= x.c; k++)
{
if(x.a[i][k] == ) continue;
for(int j = ; j<= y.c; j++)
z.a[i][j] = (z.a[i][j] + (x.a[i][k] * y.a[k][j]) % MOD) % MOD;
}
}
return z;
}
void Matrix_mod(int n)
{
while(n)
{
if(n & )
res = multi(ori, res);
ori = multi(ori, ori);
n >>= ;
}
printf("%lld\n", res.a[][] % MOD);
} int main()
{
int T, n, m;
scanf("%d", &T);
while(T--)
{
scanf("%d%d%d", &n, &m, &MOD);
LL pos = __gcd(n+, m+);
init();
Matrix_mod(pos);
}
return ;
}
华中农业大学第五届程序设计大赛网络同步赛-D的更多相关文章
- 华中农业大学第五届程序设计大赛网络同步赛-L
L.Happiness Chicken brother is very happy today, because he attained N pieces of biscuits whose tast ...
- 华中农业大学第五届程序设计大赛网络同步赛-K
K.Deadline There are N bugs to be repaired and some engineers whose abilities are roughly equal. And ...
- 华中农业大学第五届程序设计大赛网络同步赛-G
G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...
- 华中农业大学第五届程序设计大赛网络同步赛-A
Problem A: Little Red Riding Hood Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 860 Solved: 133[S ...
- [HZAU]华中农业大学第四届程序设计大赛网络同步赛
听说是邀请赛啊,大概做了做…中午出去吃了个饭回来过掉的I.然后去做作业了…… #include <algorithm> #include <iostream> #include ...
- (hzau)华中农业大学第四届程序设计大赛网络同步赛 G: Array C
题目链接:http://acm.hzau.edu.cn/problem.php?id=18 题意是给你两个长度为n的数组,a数组相当于1到n的物品的数量,b数组相当于物品价值,而真正的价值表示是b[i ...
- 华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列
Problem G: Array C Time Limit: 1 Sec Memory Limit: 128 MB Description Giving two integers and and ...
- 华中农业大学第四届程序设计大赛网络同步赛 J
Problem J: Arithmetic Sequence Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1766 Solved: 299[Subm ...
- 华中农业大学第四届程序设计大赛网络同步赛 I
Problem I: Catching Dogs Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1130 Solved: 292[Submit][St ...
随机推荐
- 「PKUSC2018」星际穿越(倍增)
倍增好题啊! 我们我们预处理 \(f[x][i]\) 表示 \(x\) 点最左到达的端点,\(sum[x][i]\) 表示 \(x\) 点最左到达的端点时 \(f[x][i]\sim x\) 的答案, ...
- [EXP]WordPress Core 5.0 - Remote Code Execution
var wpnonce = ''; var ajaxnonce = ''; var wp_attached_file = ''; var imgurl = ''; var postajaxdata = ...
- 剑指offer十六之合并两个排序的链表
一.题目 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 二.思路 注:链表1和链表2是两个递增排序的链表,合并这两个链表得到升序链表为链表3. 首先分析 ...
- 利用matlab求图像均值和方差的几种方法
一.求均值 % 求一副灰度图像的均值 close all; clear; clc; i=imread('d:/lena.jpg'); %载入真彩色图像 i=rgb2gray(i); %转换为灰度图 i ...
- 详解C#泛型(三)
一.前面两篇文章分别介绍了定义泛型类型.泛型委托.泛型接口以及声明泛型方法: 详解C#泛型(一) 详解C#泛型(二) 首先回顾下如何构建泛型类: public class MyClass<T&g ...
- 前端组件化Polymer入门教程(2)——Hello world
本节为体验篇,就是让你了解它有哪些功能,不做详细说明,后面再来讲细节. 自定义元素 组件页 <link rel="import" href="../polymer- ...
- 作用域中LHS查询和RHS查询
LHS查询:赋值操作左侧的查询,LHS查询试图找到变量的容器本身,,从而对其赋值. RHS查询:赋值操作右侧的查询,可以理解为"取到某某的值" 举例: function foo(a ...
- JavaScript中十种一步拷贝数组的方法
JavaScript中我们经常会遇到拷贝数组的场景,但是都有哪些方式能够来实现呢,我们不妨来梳理一下. 1.扩展运算符(浅拷贝) 自从ES6出现以来,这已经成为最流行的方法.它是一个很简单的语法,但是 ...
- 装饰者模式——Java设计模式
装饰模式 1.概念 动态地为对象附加上额外的职责 其目的是包装一个对象,从而可以在运行时动态添加新的职责.每个装饰器都可以包装另一个装饰器,这样理论上来说可以对目标对象进行无限次的装饰. 2.装饰器类 ...
- centos 修改时区
# date 2014年 07月 22日 星期二 :: EDT # cat /etc/sysconfig/clock -------------------------- ZONE="Ame ...