-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1342.cpp
96 lines (89 loc) · 4.16 KB
/
1342.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* |\ | | ||\ \ /(_~ |~)|_~|\/||_~|\/||~)|_~|~)
|~\|_|/\||~\ | ,_) |~\|__| ||__| ||_)|__|~\
\ //~\| | |\ |~)|_~ | ||\ ||/~\| ||_~
| \_/\_/ |~\|~\|__ \_/| \||\_X\_/|__
(J U S T L I K E E V E R Y O N E E L S E !)
__ ,..---.._
+''''`--''-..`--..__
.\ _,/:i--._`:-:+._`.``-._
/`.._,,' \ `-.``--:.b....=.
|`..__,,..`. '`.__::i--.-::_
)- .....--i'\.. --+`'''-'
,' .'.._,.-'|._-b\
/,'<' V `oi| \ _.
|/ -|,--.." ,'-. ||\.. _.,;:'_<'
''/ | . ' |\||'\ /-'_/' `.
|,','| , . .-.|:.`. + .,:.. |
._,:'/ /-\ '^' -Y"\ |.| || /,+8d| |
.|/,'| |/':: ':=:' ,'| | | \|| "+)=' |
|+,';' /|_/ \ _/ \b':.\ \'| .|| ,'
,,:-i''_i' | ``-.Y',. ,|`: | \;- | |_,'
__ |'| |i:'._ ,' ,' ,; | |-)-' __--:b__
.P| | |/,'|\ - ._ / / _,Y- ,:/' `. `'".._
,'|| -','' | ._i._ `':| ,..,' ,Y;' \ `- ._
|||||,.. | \ '-.._ _,' / _,b-' `. '-.
||||P..i, .| '....,-' _,'''''-''' ' _,.. `\
+'` <'/ |`-.....---' ._ ,._
| | ,'``,:-''''/,--`.
Y|.b_,,: | || ,;,Y' / |.
,' /'----' .'| .. | | '" .`Y' .,-b_....;;,.
|+|,' | | \., ' ,' `:. _ ,/__` _=: _,'``-
/ +,' | /\_........:.' '"----:::::'Y .'.| |||
|' ' .'/- \ /'|| || | |||
||| /| \L /'|| ||/ | |||
`.| ,'/ .| / ,'||/o;/ |||
`..._,, | |/| ' |||
``-' | |, |||
| ,. | |||
,=--------.... | "" | |||
,/,'. i=..+._ ,.. '..;---:::''- | |
'/| __....b `-''`---....../.,Y'''''j:.,.._ | `._
.' _.Y.-' `.. ii:,'--------' | :-+. .| | b\
| .=_,.---'''''--...:..--:' / _..-----..:= | | '|\
| '-''`'--- ---'_,,,--'' `,.. | | \.
\ . ,' _,--'' :dg: _,/ ||| | \
`::b\` _,-i,-' ,..---' ,|:| | _|
`'--.:-._ ____,,,;.,'' `--._ '''''''' |'|' .' '
``'--....Y''-' `''--..._..____._____...,' | 'o-'
`''''`'''i==_+=_=i__
||'''- ' `.
`-.......-''
*/
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define LL long long
#define mod 998244353
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
#define ROF(i, j, k) for (int i=j ; i>=k ; i--)
const long long INF = 1e18;
const long long MAX = 1e5+10;
int main(){
fastio;
int t=1; cin>>t;
while(t--){
int a,b,q; cin>>a>>b>>q;
if(a>b) swap(a,b);
// int m = (a*b)/__gcd(a,b);
// FOR(i,0,q){
// LL l,r; cin>>l>>r;
// LL seg1 = ((l-1)/m)*(m-b),seg2=(r/m)*(m-b);
// seg1+=max((LL)0,(l-1)%m-b+1); seg2+=max((LL)0,r%m-b+1);
// cout<<seg2-seg1<<" ";
// }
int cnt[a*b+7]={0};
FOR(i,1,a*b){
cnt[i]=cnt[i-1];
if((i%a)%b == (i%b)%a) {cnt[i]++;}
cout<<cnt[i]<<" ";
}cout<<"\n";
FOR(i,0,q){
LL l,r; cin>>l>>r;
LL s2=r/(a+b),s1=(l-1)/(a+b);
s1*=cnt[a+b-1],s2*=cnt[a+b-1];
s1+=cnt[(l-1)%(a+b)];s2+=cnt[r%(a+b)];
cout<<(r-l+1) - s2+s1<<" ";
}
cout<<"\n";
}
}