It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld (等差数列求和取模)

时间:2022-01-31 19:24:26

题目链接:

D - It's a Mod, Mod, Mod, Mod World

Kattis - itsamodmodmodmodworld

具体的每个参数的代表什么直接看题面就好了。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 2e6+;
ll cal(ll a, ll b,ll c,ll n){
if(n<=)return ;
if(n==)return (b/c);
ll tmp=;
tmp+=(a/c)*((n-)*n/);
tmp+=(b/c)*n;
a=a%c;
b=b%c;
if(a==)return tmp;
else return (tmp+cal(c,(a*n+b)%c,a,(a*n+b)/c));
}
int main(){
int T;
scanf("%d",&T);
while(T--){
ll p,q,n;
scanf("%lld %lld %lld",&p,&q,&n);
ll tot=n*(p+p*n)/2ll;
ll tmp=cal(p,p,q,n);
tmp*=q;
printf("%lld\n",tot-tmp);
}
return ;
}