Advertisement
RusSimona

Atestat 3

Feb 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int div2(int n)
  5. {
  6. int nr=0;
  7.  
  8. if(n<2)
  9. {
  10. return 0;
  11. }
  12.  
  13. while(n%2==0)
  14. {
  15. nr++;
  16. n=n/2;
  17. }
  18.  
  19. return nr;
  20. }
  21.  
  22. int div5(int n)
  23. {
  24. int nr=0;
  25.  
  26. if(n<5)
  27. {
  28. return 0;
  29. }
  30.  
  31. while(n%5==0)
  32. {
  33. nr++;
  34. n=n/5;
  35. }
  36.  
  37. return nr;
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43. int a,b;
  44. int nr5=0,nr2=0;
  45.  
  46.  
  47. cin>>a;
  48.  
  49. while(a!=0)
  50. {
  51. int b;
  52. int d2=div2(a);
  53. int d5=div5(a);
  54.  
  55.  
  56. nr2+=d2;
  57.  
  58. nr5+=d5;
  59.  
  60. cin>>b;
  61. a=b;
  62.  
  63.  
  64. }
  65. if(nr2<nr5)
  66. cout<<nr2;
  67. else cout<<nr5;
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement