SCUT - 161 - Light Tour - Mathematics

https://scut.online/p/161

It is clear that a probability number is the number of switches is his share factor.

Then very clear that in fact this is a binomial probability the total sum.

This process is a simulation WA 8 rounds. Normal, after all, floating point error accumulation is relatively large.

In fact, since it is this odd term binomial sum, it can be like high school as by the binomial theorem to (x + y) ^ k is substituted into the correct x and y eliminate unwanted items.

By analog is not up to the accuracy of the formula. Even large m seems there will be some strange bug.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1000000;

int d[MAXN], a[MAXN], maxd;
int pri[MAXN], pritop;

bool notpri[MAXN];
void init1(int n = MAXN) {
    notpri[1] = d[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!notpri[i])
            pri[++pritop] = i, d[i] = 2, a[i] = 1;
        for(int j = 1; j <= pritop && i * pri[j] <= n; j++) {
            notpri[i * pri[j]] = 1;
            if(i % pri[j])
                d[i * pri[j]] = d[i] * d[pri[j]], a[i * pri[j]] = 1;
            else {
                d[i * pri[j]] = d[i] / (a[i] + 1) * (a[i] + 2);
                a[i * pri[j]] = a[i] + 1;
                break;
            }
        }
    }
    maxd = 240;
}
int n, m;

long double ans2[250], p, q;

void init2() {
    int c = min(n, maxd);
    for(int i = 1; i <= c; ++i) {
        p = (long double)i / (long double)n, q = 1.0 - p;
        if(m & 1)
            ans2[i] = (pow(p + q, m) + pow(p - q, m)) / (2.0);
        else
            ans2[i] = 1.0 - ((pow(p + q, m) + pow(p - q, m)) / (2.0));
    }
}

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    init1();
    while(~scanf("%d%d", &n, &m)) {
        init2();
        for(int i = 1; i <= n; ++i)
            printf("%.8f%c", (double)ans2[d[i]], " \n"[i == n]);
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/Yinku/p/11333747.html