其他分享
首页 > 其他分享> > CodeForces 1389 E Calendar Ambiguity

CodeForces 1389 E Calendar Ambiguity

作者:互联网

https://codeforc.es/problemset/problem/1389/E

其实就是让你列公式自己算一次,

(x*d - d + y) %w = (y*d - d + x)%w

 

最后化简成 : (d-1)*(y - x)%w = 0;

 

可知y-x(y > x)必须是w/gcd (d-1,w)的倍数

可以说是很巧妙了吧。x和y的范围必须是len = min(d,m)

 

假设f(a)表示y-x=a时y的可选个数,f (a) = len - a

答案就是sigm f(i)        for( i = x;i<=len;i+=x);

简化一下

具体看代码就好

 

 

#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 2e5+11;
typedef long long ll;
ll len;
ll f(ll x){
	return len - x;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		ll m,d,w;
		cin>>m>>d>>w;
		
		len = min(m,d);
		
		ll x = __gcd(d-1,w);
		x = w/x;
		
		ll ans = 0;
		ll n = len/x;
		ans = n*len - n*(n+1)*x/2;
		cout<<ans<<endl;
		
	}
	return 0;
}

  

标签:gcd,int,ll,CodeForces,len,Ambiguity,ans,Calendar,include
来源: https://www.cnblogs.com/lesning/p/13919601.html