a53

Sum Triunghiular

a53
Dec 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void tri(unsigned long long n)
  5. {
  6. unordered_set<unsigned long long> tri;
  7. unsigned long long i=1;
  8. while(1)
  9. {
  10. unsigned long long x=i*(i+1)/2;
  11. if(x>=n)
  12. break;
  13. tri.insert(x);
  14. i++;
  15. }
  16. for(auto tm : tri)
  17. if(tri.find(n-tm)!=tri.end())
  18. {
  19. cout<<n-tm<<" "<<tm;
  20. exit(0);
  21. }
  22. cout<<"NU";
  23. exit(0);
  24. }
  25.  
  26. int main()
  27. {
  28. unsigned long long n;
  29. cin>>n;
  30. tri(n);
  31. }
Add Comment
Please, Sign In to add comment