Educational Codeforces Round 86 (Rated for Div. 2) C—Yet Another Counting Problem
Posted qingyuyyyyy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 86 (Rated for Div. 2) C—Yet Another Counting Problem相关的知识,希望对你有一定的参考价值。
//序列具有周期性
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=5e4+10;
ll sum[N];
ll a,b,q;
ll calc(ll x)
{
return x/(a*b)*sum[a*b]+1ll*sum[x%(a*b)];
}
void solve()
{
memset(sum,0,sizeof sum);
cin>>a>>b>>q;
for(int i=1;i<=a*b;i++)
sum[i]+=sum[i-1]+(i%a%b!=i%b%a);
while(q--)
{
ll l,r;
cin>>l>>r;
cout<<calc(r)-calc(l-1)<<" ";
}
cout<<endl;
}
int main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
以上是关于Educational Codeforces Round 86 (Rated for Div. 2) C—Yet Another Counting Problem的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 7 A
Educational Codeforces Round 7
Educational Codeforces Round 90
Educational Codeforces Round 33