fork(1) download
  1. #include<bits/stdc++.h>
  2. #define FOR(i,a,b,k) for (ll i=a;i<=b;i+=k)
  3. #define FORD(i,a,b,k) for (ll i=a;i>=b;i-=k)
  4. #define pb(i) push_back(i)
  5. #define ll long long int
  6. #define MOD 1000000007
  7. #define lim 1e16
  8. using namespace std;
  9. ll a,b,c,res=0;
  10.  
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(false);
  14. cin.tie(NULL);cout.tie(NULL);
  15. cin>>a>>b>>c;
  16.  
  17. if(c%2==0)
  18. {
  19. if(a%2==0) {res++;a++;}
  20. if(b%2==0) {res++;b--;}
  21.  
  22. res+=(b-a)/2;
  23. }
  24. else
  25. {
  26. ll them_a=c-1-a%c;
  27. ll chuky=(c+1)/2;
  28. ll tanso=(b-a)/c;
  29.  
  30. a+=them_a+tanso*c;
  31. res+=them_a/2+them_a%2+tanso*chuky;
  32.  
  33. res+=(b-a)/2+(b-a)%2;
  34. }
  35.  
  36. cout<<res;
  37. return 0;
  38. }
Success #stdin #stdout 0s 5580KB
stdin
Standard input is empty
stdout
1