Skip to content

Instantly share code, notes, and snippets.

@viliml
Last active April 21, 2016 10:20
Show Gist options
  • Save viliml/daf035256ba8614503a93200c17bfc19 to your computer and use it in GitHub Desktop.
Save viliml/daf035256ba8614503a93200c17bfc19 to your computer and use it in GitHub Desktop.
HONI '13
#include <bits/stdc++.h>
using namespace std;
#define double long long
double gcd(double a, double b)
{
double tmp;
while (b)
{
tmp = b;
b = a % b;
a = tmp;
}
return a;
}
double lcm(int n)
{
double ret = 1;
for (int i = 2; i <= n; ++i)
ret *= i / gcd(ret, i);
return ret;
}
double arr[4];
double calc(double n)
{
double ret = 2 * n;
ret += n / 2;
for (int i = 0; i < 4; ++i)
{
double k = arr[i];
ret += n / k + (n % k >= k / 2);
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for (int i = 0; i < 4; ++i)
arr[i] = lcm(4<<i);
double a, b;
cin>>a>>b;
cout<<calc(b) - calc(a - 1)<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment