Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int najwiekszy(int a, int b)
  6. {
  7. while (a!=b) {
  8. if(a>b)
  9. a-=b;
  10. else
  11. b-=a;
  12. }
  13. return a;
  14. }
  15.  
  16. int main()
  17. {
  18. int i = 2;
  19. int suma = 0;
  20. int x;
  21. int o1;
  22. cin>>o1;
  23. int o2;
  24. cin>>o2;
  25. while (i<1000000000) {
  26. cin>>x;
  27. if (x==1) {
  28. suma += najwiekszy(o1, o2);
  29. }
  30. else if (x==0) {
  31. break;
  32. }
  33. else if (x>1){
  34. o1 = o2;
  35. o2 = x;
  36. i++;
  37. }
  38. }
  39. cout<<suma;
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement