【YBTOJ】序列的第k个数

序列的第 k 个数

题目大意:

给你序列的前三项,这个序列要么是等差序列,要么是等比序列,求出第 \(k\) 项的值。

代码:

const int mod = 200907;

inline ll Read()
{
	ll x = 0, f = 1;
	char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = -f, c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
	return x * f;
}

int t;
ll a, b, c, n;

ll qpow(ll a, ll b)
{
	ll ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1) ans = ans * a % mod;
	return ans;
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	for (t = Read(); t--; )
	{
		a = Read(), b = Read(), c = Read(), n = Read();
		if (b - a == c - b)
			printf ("%lld\n", (a + (b - a) * (n - 1) % mod) % mod);
		else printf ("%lld\n", a * qpow(b / a, n - 1) % mod);
	}
	return 0;
}

posted @ 2021-08-10 21:11  Jayun  阅读(71)  评论(0编辑  收藏  举报