码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 86 (Rated for Div. 2) C—Yet Another Counting Problem

时间:2020-04-29 18:21:24      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:long   type   memset   cat   cout   tin   cin   a*   pre   

//序列具有周期性 
#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

标签:long   type   memset   cat   cout   tin   cin   a*   pre   

原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12803313.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!