题目1442:A sequence of numbers
arithmetic sequences:等差数列
geometric sequences:等比数列
代码如下:
#include <stdio.h>
#define M 200907
long long geoSeq(long long a, long long q, int k)
{
long long ans = a;
k -= 1;
while (k)
{
if (k & 1){
ans *= q;
ans %= M;
}
q *= q;
q %= M;
k >>= 1;
}
return ans;
}
long long arithSeq(long long a, long long d, int k)
{
int ans = a % M + ((k - 1)*d) % M;
return ans %= M;
}
int main()
{
int n;
scanf("%d", &n);
while (n--)
{
long long a, b, c;
int k;
scanf("%lld%lld%lld%d", &a, &b, &c, &k);
long long ans;
if (a*c == b*b)
ans = geoSeq(a, c / b, k);
else
ans = arithSeq(a, c - b, k);
printf("%lld\n", ans);
}
return 0;
}