Cod sursa(job #2148926)
| Utilizator | Data | 2 martie 2018 10:09:11 | |
|---|---|---|---|
| Problema | Zero 2 | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.05 kb |
#include <fstream>
using namespace std;
ifstream fin("zero2.in");
ofstream fout("zero2.out");
long long p;
long long cmmfp(long long x)
{
p = 0;
while(!(x & 1)) {
p++;
x >>= 1;
}
if(x == 1)
return 2;
else {
int d = 3;
while(d * d <= x && x > 1) {
if(x % d) {
d += 2;
continue;
}
p = 0;
while(!(x % d)) {
x /= d;
p++;
}
d += 2;
}
if(x > 1) {
p = 1;
return x;
}
else
return d - 2;
}
}
int main()
{
int t = 10;
while(t--) {
long long n, b, x, nr = 0;
fin >> n >> b;
x = cmmfp(b);
b = x;
while(b <= n) {
int k = n / b;
nr += (((n + 1 - b) * 2 - (k - 1) * b) * k) / 2;
b *= x;
}
fout << nr / p << '\n';
}
return 0;
}
