Advertisement
a53

regula

a53
Nov 20th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. long long c,v,s,grup,i;
  5.  
  6. int main ()
  7. {
  8. cin>>c>>v;
  9. if(c==1)
  10. { /// aflam valoarea de pe pozitia v
  11. s = 0;
  12. for(grup=1;;++grup)
  13. {
  14. s += grup+(grup+1)/2;
  15. if(s>=v)
  16. break;
  17. }
  18. s-=(grup+(grup+1)/2);
  19. v-=s;
  20. if(v<=grup) /// ne intereseaza valoarea de pe pozitia v din grupul grup
  21. cout<<v<<'\n';
  22. else
  23. {
  24. v-=grup;
  25. cout<<2*v-1<<'\n';
  26. }
  27. }
  28. else
  29. { /// c=2
  30. for (i=1;i<=v-1;i++)
  31. s+=i+(i+1)/2;
  32. cout<<s+v<<'\n';
  33. }
  34. return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement