fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. unsigned NWD(unsigned a,unsigned b)
  5. {
  6. while (b!=0)
  7. {
  8. unsigned r=a%b;
  9. a=b;
  10. b=r;
  11. }
  12. return a;
  13. }
  14.  
  15. int main()
  16. {
  17. unsigned sum=0,a=0,b=0;
  18. while(true)
  19. {
  20. unsigned c;
  21. cin>>c;
  22. if(!c) break;
  23. if(c>1)
  24. {
  25. a=b;
  26. b=c;
  27. }
  28. else sum+=NWD(a,b);
  29. }
  30. cout<<sum;
  31. return 0;
  32. }
Success #stdin #stdout 0s 3344KB
stdin
5 5 4 4 1 5 5 1 4 4 1 1 1 5 4 3 2 1 0
stdout
22