Created
June 13, 2016 10:44
-
-
Save viliml/785211fde7ea1696c8799b994e9bb1a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long llint; | |
int A, B, L; | |
llint f(int dy) | |
{ | |
if (dy == 0) | |
return 1; | |
llint sol = 0; | |
vector<int> divs; | |
if (dy % 2 == 0) | |
{ | |
divs.push_back(2); | |
while (dy % 2 == 0) | |
dy /= 2; | |
} | |
for (int d = 3; d <= dy; d += 2) | |
{ | |
if (dy % d == 0) | |
{ | |
divs.push_back(d); | |
while (dy % d == 0) | |
dy /= d; | |
} | |
} | |
for (int bit = 0; bit < (1<<divs.size()); ++bit) | |
{ | |
int x = 1, sgn = 1; | |
for (int i = 0; i < divs.size(); ++i) if (bit & 1<<i) | |
{ | |
x *= divs[i]; | |
sgn = -sgn; | |
} | |
sol += sgn * L / x; | |
} | |
return sol; | |
} | |
llint s1(int y) | |
{ | |
return f(y + A); | |
} | |
llint s2(int y) | |
{ | |
return f(B - y); | |
} | |
llint s12(int y) | |
{ | |
return f((y + A) * (B - y)); | |
} | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
int a, b, c; | |
llint ns = 0, s = 0, ss = 0; | |
cin>>A>>B>>L; | |
for (int y = -A; y <= B; ++y) | |
{ | |
a = s1(y); | |
b = s2(y); | |
c = s12(y); | |
ss += c; | |
s += a + b - 2 * c; | |
ns += L - a - b + c; | |
} | |
cout<<ns<<endl<<s<<endl<<ss<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment