Advertisement
a53

w_i_s_p

a53
May 13th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <fstream>
  2. #define ULL unsigned long long
  3. using namespace std;
  4.  
  5. void suma(ULL n,ULL s,ULL pas,ULL &sol) /// Calculez suma recursiv
  6. {
  7. if(s<n*n-4)
  8. s+=pas,sol+=s,s+=pas,sol+=s,suma(n,s,pas-4,sol);
  9. }
  10.  
  11. int main()
  12. {
  13. ifstream f("wisp.in");
  14. ULL n,k;
  15. f>>n>>k;
  16. f.close();
  17. ULL s=1,sol=0,pas=2*(n-1); /// pas=pasul initial
  18. sol=n*(k-1)+1; /// Corectez valorea pentru k;
  19. suma(n,s,pas,sol);
  20. if(n%2==0) /// Pentru n par
  21. sol+=n*n-1; /// iau in calcul si ultima valoare
  22. ofstream g("wisp.out");
  23. g<<sol;
  24. g.close();
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement