fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. class DreamingAboutCarrots{
  4. public:
  5. int carrotsBetweenCarrots(int x1, int y1, int x2, int y2){
  6. if(x1 == y1 && x2 == y2)return(max(x1,x2)-min(y1,y2))-1;
  7. int cnt=0;
  8. for(int x=min(x1,x2) ; x<=max(x1,x2) ; x++){
  9. for(int y=min(y1,y2) ; y<= max(y1,y2) ; y++){
  10. if((y* (x2-x1)) == ( (x *(y2-y1)) - (x2 *(y2-y1))) + (y2 *(x2-x1)))cnt++;
  11. }
  12. }
  13. return (cnt-2);
  14. }
  15. };
  16. int main()
  17. {
  18. ios::sync_with_stdio(0);
  19. cin.tie(),cout.tie();
  20. int a,b,c,d;
  21. cin>>a>>b>>c>>d;
  22. DreamingAboutCarrots ob;
  23. cout<<ob.carrotsBetweenCarrots(a,b,c,d);
  24. }
  25.  
Success #stdin #stdout 0s 3276KB
stdin
0
0
36
42
stdout
5