ans shrtest way, no comments in code C. Joyboard time limit per test1 second memory…
- User
ans shrtest way, no comments in code C. Joyboard time limit per test1 second memory limit per test256 megabytes Chaneka, a gamer kid, invented a new gaming controller called joyboard. Interestingly, the joyboard she invented can only be used to play one game.
The joyboard has a screen containing n+1 slots numbered from 1 to n+1 from left to right. The n+1 slots are going to be filled with an array of non-negative integers [a1,a2,a3,…,an+1] . Chaneka, as the player, must assign an+1 with an integer between 0 and m inclusive. Then, for each i from n to 1 , the value of ai will be equal to the remainder of dividing ai+1 (the adjacent value to the right) by i . In other words, ai=ai+1modi .
Chaneka wants it such that after every slot is assigned with an integer, there are exactly k distinct values in the entire screen (among all n+1 slots). How many valid ways are there for assigning a non-negative integer into slot n+1 ?
Input Each test contains multiple test cases. The first line contains an integer t (1≤t≤2⋅104 ) — the number of test cases. The following lines contain the description of each test case.
The only line of each test case contains three integers n , m , and k (1≤n≤109 ; 0≤m≤109 ; 1≤k≤n+1 ) — there are n+1 slots, the integer assigned in slot n+1 must not be bigger than m , and there should be exactly k distinct values.
Output For each test case, output a line containing an integer representing the number of valid ways for assigning a non-negative integer into slot n+1 .
Example InputCopy 4 4 6 3 2 0 1 265 265 265 3 10 2 OutputCopy 2 1 0 5 Note In the first test case, one of the 2 possible ways for Chaneka is to choose an+1=6 . If she does that, then:
a4=a5mod4=6mod4=2 a3=a4mod3=2mod3=2 a2=a3mod2=2mod2=0 a1=a2mod1=0mod1=0 a=[0,0,2,2,6] There are 3 distinct values. In the second test case, the 1 possible way for Chaneka is to choose an+1=0 . If she does that, then a=[0,0,0] . There is only 1 distinct value.
In the third test case, there is no possible way for assigning a non-negative integer into slot n+1 .
must use #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { ios::sync_with_stdio(false); cin.tie(0); /// }
- Assistantcpp
#include <bits/stdc++.h> #define int long long using namespace std; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--){ int n, m, k; cin>>n>>m>>k; if(k ==1){ cout<<(m >=0 ? 1 : 0)<<"\n"; } else{ // Calculate k2 int k2 = min(n, m); if(n+1 >0){ k2 += m / (n+1); } if(k ==2){ cout<<k2<<"\n"; } else{ // Calculate k1 int k1 = (m >=0) ? 1 : 0; // Calculate total distinct int total = m+1; // Calculate answer int ans = total - k1 - k2; if(ans <0) ans=0; if(k >=3 && k <= n+1){ cout<<ans<<"\n"; } else{ cout<<0<<"\n"; } } } } }