[Cometoj#4 B]奇偶性_打表
奇偶性
题目链接:https://cometoj.com/contest/39/problem/B?problem_id=1577
数据范围:略。
题解:
因为$f$的构造原因,很容易找到规律。
进而得出答案。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; char *p1, *p2, buf[100000]; #define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ ) ll rd() { ll x = 0; char c = nc(); while (c < 48) { c = nc(); } while (c > 47) { x = (((x << 2) + x) << 1) + (c ^ 48), c = nc(); } return x; } ll solve(ll n, ll k) { if (k & 1) { return n; } else { return n / (k + 1) * k + n % (k + 1); } } int main() { int T = rd(); while (T -- ) { ll l = rd() + 1, r = rd() + 1, k = rd(); printf("%lld\n", solve(r, k) - solve(l - 1, k)); } return 0; }
| 欢迎来原网站坐坐! >原文链接<