Description Input Output 每组输出一个整数表示答案 Sample Input 1
4 6 2
Sample Output 48
Hint Source “科林明伦杯”哈尔滨理工大学第13届程序设计团队赛
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define int long long
typedef pair<int,int>PII;
constexpr int N = 2,mod=1e9+7;
int gcd(int a,int b){
return b ? gcd(b,a%b):a;
}
void extend_gcd(int a,int b,int &x,int &y){
if(b==0){
x=1,y=0;
return;
}
extend_gcd(b,a%b,x,y);
int tem=x;
x=y;
y=tem-(a/b)*y;
}
int mod_inv(int a,int mod){
int x,y;
extend_gcd(a,mod,x,y);
return (x%mod+mod)%mod;
}
void mul(int c[], int a[], int b[][N])
{
int temp[N] = {0};
for (int i = 0; i < N; i++) // i代表的是坐标
{
for (int j = 0; j < N; j++) // j代表操作;
{
temp[i] = (temp[i] + a[j] * b[j][i]) % mod;
}
}
memcpy(c, temp, sizeof temp);
}
void mul(int c[][N], int a[][N], int b[][N])
{
int temp[N][N] = {0};
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
for (int k = 0; k < N; k++)
{
temp[i][j] = (temp[i][j] + a[i][k] * b[k][j]) % mod;
}
}
}
memcpy(c, temp, sizeof temp);
}
signed main()
{
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
int t1,t2,k;
cin>>t1>>t2>>k;
int f1[3] = {t1,t2};
int A[N][N] = {
{0, 1,},
{1, 2},
};
k--;
while (k)
{
if (k & 1)
{
mul(f1, f1, A);
}
mul(A, A, A);
k >>= 1;
}
int d=gcd(t1,t2);
d=mod_inv(d,mod);
int c=f1[0]*f1[1]%mod;
cout<<(c*d)%mod<<endl;
}
return 0;
}