Codeforces 1342 C. Yet Another Counting Problem(找规律)_预处理

题意:

Codeforces 1342 C. Yet Another Counting Problem(找规律)_预处理_02 范围内多少个数满足 Codeforces 1342 C. Yet Another Counting Problem(找规律)_预处理_03

一般这种题没什么思路就打表找一下规律。

7
8
9
10
11
12
13
14
15
16
17
18
19
20
28
29
30
31
32
33
34
35
36
37
38
39
40
41
49
50
51
52
53
54
55
56
57
58
59
60
61
62
70
71
72
73
74
75
76
77
78
79
80
81
82
83
91
92
93
94
95
96
97
98
99
100

可以发现当为 Codeforces 1342 C. Yet Another Counting Problem(找规律)_打表_04 倍数的时候,再连续 Codeforces 1342 C. Yet Another Counting Problem(找规律)_打表_05 个数字,是那个式子满足相等的。说明循环周期是一个 Codeforces 1342 C. Yet Another Counting Problem(找规律)_预处理_06

AC代码:

const int N = 40010;
ll a, b, q, lc;
ll s[N];
ll ans;
void init()
{
rep(i, 1, lc)
s[i] = s[i - 1] + (i % a % b != i % b % a);//预处理
}

ll cal(ll x)
{
return s[lc] * (x / lc) + s[x % lc];
}

int main()
{
int t;
sd(t);
while (t--)
{
slddd(a, b, q);
lc = lcm(a, b);
init();
while (q--)
{
int l, r;
sdd(l, r);
ans = cal(r) - cal(l - 1);
printf("%lld ", ans);
}
printf("\n");
}
return 0;
}