HDU-2817-A sequence of numbers
hh,这道题是逆元哈~
我当时看这道题目就看的一脸离谱emmm。
我不知道arithmetic or geometric sequences是什么意思。。。谷歌翻译了一下。他说是什么算术序列或集合序列?我内心:???这是啥?
后来才知道是等差数列或者等比数列的意思emmm.
我来复习快速幂啦~。
这次精细一点~
虽然这道题就是个模板题: )
我这道题直接用的__int64,你知道吗,__int64就特别离谱。hhh可爽了,这个东西还是我有一次打牛客竞赛的时候看到的。哇。当时就惊呆了emmm。嘻嘻估计蓝桥杯也可以用。毕竟和dev的编译器是一样的~
快速幂的思路(本来打算录个视频的emm):
快速幂部分:
__int64 npow(__int64 a, __int64 n)
{
__int64 res = 1;//储存结果
while (n)
{
if (n & 1)//当前最低位为1
{
res = res * a % mod;//乘上
}
a = a * a % mod;//表示a^1, a^2, a^4, a^8...
n >>= 1;//右移一位,去掉最后一位
}
return res;
}
嘻嘻这个操作强大!
代码部分:
#include <bits/stdc++.h>
using namespace std;
const int mod = 200907;
__int64 npow(__int64 a, __int64 n)
{
__int64 res = 1;
while (n)
{
if (n & 1)
{
res = res * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return res;
}
int main()
{
__int64 n, a, b, c, k;
cin >> n;
while (n--)
{
cin >> a >> b >> c >> k;
if (b - a == c - b)
{
int d = b - a;
cout << (a + d * (k - 1)) % mod << endl;
}
else
{
int q = b / a;
cout << a * npow(q, k - 1) % mod << endl;
}
}
return 0;
}