Submission #41856992


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
ll T,n,m,r;

ll S(ll n){return n*(n+1)/2;}
ll f(ll a,ll b,ll c,ll n){
	if(n<0)return 0;
	if(n==0)return a/c;

	if(a>=c || b>=c){
		return (a/c) * (n+1) + (b/c) * S(n) + f(a%c,b%c,c,n);
	}
	ll m = (a+n*b)/c;
	return n*m - f(c-a-1,c,b,m-1);
}

ll p[35];

void solve(){
	cin>>n>>m>>r;

	ll ans = 0;
	rep(i,0,30){
		p[i] = f(r,m,1<<i,(n-r)/m);
	}
	rep(i,0,30){
		ans += (p[i] - 2*p[i+1]);
	}
	cout<<ans<<"\n";
}

int main(){
	cin>>T;
	while(T--)solve();

    return 0;
}

Submission Info

Submission Time
Task Ex - Popcount Sum
User Crying
Language C++ (GCC 9.2.1)
Score 600
Code Size 900 Byte
Status AC
Exec Time 688 ms
Memory 3636 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 30
Set Name Test Cases
Sample example0.txt
All example0.txt, random0.txt, random1.txt, random10.txt, random11.txt, random12.txt, random13.txt, random14.txt, random15.txt, random16.txt, random17.txt, random18.txt, random19.txt, random2.txt, random20.txt, random21.txt, random22.txt, random23.txt, random24.txt, random25.txt, random26.txt, random27.txt, random3.txt, random4.txt, random5.txt, random6.txt, random7.txt, random8.txt, random9.txt, small0.txt
Case Name Status Exec Time Memory
example0.txt AC 10 ms 3588 KiB
random0.txt AC 361 ms 3592 KiB
random1.txt AC 612 ms 3632 KiB
random10.txt AC 688 ms 3592 KiB
random11.txt AC 665 ms 3524 KiB
random12.txt AC 684 ms 3584 KiB
random13.txt AC 667 ms 3632 KiB
random14.txt AC 679 ms 3440 KiB
random15.txt AC 662 ms 3596 KiB
random16.txt AC 670 ms 3596 KiB
random17.txt AC 654 ms 3524 KiB
random18.txt AC 662 ms 3564 KiB
random19.txt AC 644 ms 3572 KiB
random2.txt AC 652 ms 3620 KiB
random20.txt AC 646 ms 3596 KiB
random21.txt AC 625 ms 3444 KiB
random22.txt AC 352 ms 3552 KiB
random23.txt AC 527 ms 3636 KiB
random24.txt AC 526 ms 3460 KiB
random25.txt AC 526 ms 3584 KiB
random26.txt AC 526 ms 3580 KiB
random27.txt AC 528 ms 3560 KiB
random3.txt AC 635 ms 3620 KiB
random4.txt AC 670 ms 3524 KiB
random5.txt AC 654 ms 3436 KiB
random6.txt AC 683 ms 3452 KiB
random7.txt AC 663 ms 3452 KiB
random8.txt AC 684 ms 3440 KiB
random9.txt AC 666 ms 3552 KiB
small0.txt AC 222 ms 3564 KiB