LightOJ1236 Pairs Forming LCM 水题?。。

LightOJ1236 Pairs Forming LCM

label

Foreword

Concise meaning of the questions

\[\sum_{i=1}^n\sum_{j=1}^n[lcm(i,j)=n]\]

Thinking

  • Of prime factorization of n, \ (P_1 ^ n = {C1} ^ {P_2 P_K c_2} ... {C_K} ^ \) , defined by lcm know, ij of, for each \ (P_i \) , should have \ (max (c_1 and, c_2) = C \) , therefore, the need to make a ij is c, another optional, so there \ (2c + 1 \) compounds selected method. So the answer should be \ (\ Prod (2c_i + 1) \) .
  • The answer requires a <= b, so the answer needs / 2 (and to be rounded up)

Precautions

  • no

to sum up

  • no

AC Code

#include<cstdio>

const int maxn = 1e7 + 10;

bool no_prime[maxn];
int prime[(int)7e5];
int shai(int n)
{
    int cnt = 0;
    no_prime[1] = 1;

    for (int i = 2; i <= n; i++)
    {
        if (!no_prime[i])
            prime[++cnt] = i;

        for (int j = 1; j <= cnt && prime[j] * i <= n; j++)
        {
            no_prime[prime[j] * i] = 1;
            if (i % prime[j] == 0) break;
        }
    }
    return cnt;
}

void solve()
{
    int cnt = shai(maxn - 10);

    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++)
    {
        long long n, r;
        scanf("%lld", &n);
        r = n;

        long long ans = 1;
        for (int i = 1; i <= cnt && 1ll * prime[i] * prime[i] <= r && n != 1; i++)
        {
            int cnt = 0;
            while (n % prime[i] == 0)
                n /= prime[i], cnt++;
            ans *= (2 * cnt + 1);
        }
        if (n != 1)
            ans *= 3;

        printf("Case %d: %lld\n", i, (ans + 1) / 2);
    }
}

int main()
{
    freopen("Testin.txt", "r", stdin);
    solve();
    return 0;
}

Guess you like

Origin www.cnblogs.com/danzh/p/11420164.html