Lightoj 1038-race to 1 Again (expected +DP)

Source: Internet
Author: User

Title Link: http://lightoj.com/volume_showproblem.php?problem=1038

Test instructions is: give you an n (1≤n≤105) each time n is randomly selected a factor d, and then let n=n/d, ask N to become 1 times the expectation;

When N = 2 o'clock 2 There are two factors:

E[2] = E[1]/2 + E[2]/2 + 1; So you can find e[2];

When n = 8 o'clock 8 There are 4 factors 1 2 4 8;

E[8] = E[1]/4 + E[2]/4 + E[4]/4 + e[8]/4+ 1; So you can find e[8];

......

we use e[i] to indicate that I becomes 1 of the times expected; then e[i] = e[a[1]]/cnt + e[a[2]]/cnt + ... + e[a[cnt]]/cnt + 1; (plus 1 is because this time except once );

Wherein CNT is the number of factors of I, a array of factor set I, if the order from small to large a[1] = 1, a[cnt] = i;

So the a[cnt in the upper formula] is replaced by I; the collation can be e[i] = (e[a[1]]+e[a[2]]+ ... +e[a[cnt-1]]+cnt)/(CNT-1);

#include <cstring>#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<stack>#include<vector>#include<queue>using namespacestd;#defineN 100005#defineMet (A, b) memset (A, B, sizeof (a))#defineMOD 110119typedefLong LongLL;DoubleDp[n];voidInit () {dp[1] =0;  for(intI=2; i<n; i++)    {        Doublesum =0; intCNT =0;  for(intj=1; j*j<=i; J + +)        {            if(I%j = =0) {CNT++; Sum+=Dp[j]; if(J*j! =i) {cnt++; Sum+ = dp[i/j];///J is the factor of I, i/j is also the factor of I;} }} sum+=CNT; Dp[i]= sum/(cnt-1); }}intMain () {Init (); intT, T =1, N; scanf ("%d", &T);  while(t--) {scanf ("%d", &N); printf ("Case %d:%.6f\n", t++, Dp[n]); }    return 0;}
View Code

Lightoj 1038-race to 1 Again (expected +DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.