Saleh127

CF 1409C

Sep 5th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; while(t--)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12. ll n,x,y,i,j,k,l=0,m,d,c=0;
  13. cin>>n>>x>>y;
  14. k=y-x;
  15. while(1)
  16. {
  17. l++;
  18. m=0;
  19. if(k%l==0)
  20. {
  21. for(i=x; ;i+=l)
  22. {
  23. m++;
  24. if(i==y && m<=n)
  25. {
  26. c=1;
  27. break;
  28. }
  29. if(i>y) break;
  30. }
  31.  
  32. }
  33. if(c==1)
  34. {
  35. d=l;
  36. break;
  37. }
  38. }
  39. for(i=x;i<=y;i+=d)
  40. {
  41. n--;
  42. cout<<i<<" ";
  43. }
  44. if(n==0)
  45. {
  46. cout<<endl;
  47. continue;
  48. }
  49. for(i=x-d; ;i-=d)
  50. {
  51. if(i<=0) break;
  52. cout<<i<<" ";
  53. n--;
  54. if(n==0) break;
  55. }
  56. if(n==0)
  57. {
  58. cout<<endl;
  59. continue;
  60. }
  61. for(i=y+d; ;i+=d)
  62. {
  63. cout<<i<< " ";
  64. n--;
  65. if(n==0)
  66. {
  67. cout<<endl;
  68. break;
  69. }
  70. }
  71. }
  72. return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment