Pagini recente » Cod sursa (job #3288238) | Cod sursa (job #2248935) | Cod sursa (job #1839556) | Cod sursa (job #264629) | Cod sursa (job #644557)
Cod sursa(job #644557)
#include <stdio.h>
02.#define NMAX 2000010
03.
04.long long result, nd, n, m;
05.long long div[NMAX];
06.char sieve[NMAX];
07.
08.void back(long long nr, long long k, long long pos)
09.{
10.long long i;
11.long long x;
12.long long c = (long long) (n / nr) * (m / nr);
13.
14.if (k % 2 == 1)
15.result -= c;
16.else
17.result += c;
18.
19.for (i = pos; i <= nd; ++i) {
20.x = nr * div[i];
21.if (x <= n)
22.back(nr * div[i], k + 1, i + 1);
23.else
24.return;
25.}
26.}
27.
28.int main()
29.{
30.freopen("mins.in", "r", stdin);
31.freopen("mins.out", "w", stdout);
32.long long i, j;
33.scanf("%lld %lld", &n, &m);
34.if (n > m) {
35.result = m;
36.m = n;
37.n = result;
38.}
39.--n; --m;
40.result = 0;
41.
42.nd = 0;
43.for (i = 2; i <= m; ++i)
44.if (!sieve[i]) {
45.div[++nd] = i;
46.if (i * i <= m)
47.for (j = i * i; j <= m; j += i)
48.sieve[j] = 1;
49.}
50.
51.result = 0;
52.back(1, 0, 1);
53.printf("%lld\n", result);
54.
55.return 0;
56.}