View Code of Problem 3703

#include <stdio.h>
#include <string.h>
#define LL long long

const int MAXN = 500010;

LL mod;

LL val[MAXN];
LL dp[MAXN];

void cal(int n)
{
    for(LL i = 1; i < n; i++)
    {
        for(LL j = i;j < n; j += i)
            val[j] += (j/i + 1) * (j/i) / 2;
    }
}

void init()
{
    mod = 1;
    mod = (mod << 32);
    //memset(val, 0, sizeof val);
    cal(MAXN);
    dp[1] = 1;
    for(LL i = 2; i < MAXN; i++)
    {
        dp[i] = (dp[i - 1] + val[i] * i);
        dp[i] = dp[i] % mod;
    }
}

int main()
{
    init();
    int cas = 1;
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        scanf("%d", &n);
        printf("Case #%d: %lld\n", cas++, dp[n]);
    }
    return 0;
}

/*
Main.c:9:4: error: variably modified 'val' at file scope
 LL val[MAXN];
    ^
Main.c:10:4: error: variably modified 'dp' at file scope
 LL dp[MAXN];
    ^
*/

Double click to view unformatted code.


Back to problem 3703