fork download
  1. // Coded By Vishal Mourya
  2. #include<bits/stdc++.h>
  3. #define ll long long int
  4. using namespace std;
  5.  
  6. int main(void) {
  7. ll t; cin >> t;
  8.  
  9. while(t--) {
  10. ll n,m; cin >> n >> m;
  11.  
  12. if( n == 1 ) cout << m << "\n";
  13. else {
  14. ll rem = m % n; // this will hold remianing number of candies
  15. ll add = m/n; // this will give number of candies that can be distributed, equally
  16. vector<ll> v;
  17.  
  18. for( ll i = 1 ; i <= n ; i++ ) {
  19. v.push_back(add);
  20. }
  21.  
  22. if( add % 2 == 0 ) {
  23. // The remaining candies is distributed starting from front
  24. ll index = 0;
  25. while( rem != 0 ) {
  26. v[index]++;
  27. index++;
  28. rem--;
  29. }
  30. }
  31.  
  32. if( add % 2 != 0 ){
  33. // The remaining candies is distributed starting from back
  34. ll index = v.size() - 1;
  35. while( rem != 0 ) {
  36. v[index]++;
  37. index--;
  38. rem--;
  39. }
  40. }
  41.  
  42. // Finally output the required array
  43. for( ll i = 0 ; i < v.size() ; i++ ) cout << v[i] << " ";
  44. cout << "\n";
  45. }
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 4376KB
stdin
2
3 4
5 11
stdout
1 1 2 
3 2 2 2 2