loj 1038

Posted coolwx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了loj 1038相关的知识,希望对你有一定的参考价值。

imi learned a new thing about integers, which is - any positive integer greater than 1 can be divided by its divisors. So, he is now playing with this property. He selects a number N. And he calls this D.

In each turn he randomly chooses a divisor of D (1 to D). Then he divides D by the number to obtain new D. He repeats this procedure until D becomes 1. What is the expected number of moves required for N to become 1.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case begins with an integer N (1 ≤ N ≤ 105).

Output

For each case of input you have to print the case number and the expected value. Errors less than 10-6 will be ignored.

Sample Input

3

1

2

50

Sample Output

Case 1: 0

Case 2: 2.00

Case 3: 3.0333333333

网上的题解都是错的,结果一群人再抄,笑死我了

设一个数的约数有num个,E[n] = (E[a[1]]+1)/num+(E[a[2]]+1)/num+...+(E[a[num]]+1)/num  ,而a[num]==n,于是整理得:

E[n]=(E[a[1]]+E[a[2]]+...+E[a[num-1]]+num)/(num-1)。

网上这个式子多了个+1,一群人抄的很起劲,笑死我了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

int n;
double dp[111111];

void Get_Dp()

    dp[1]=0;
    for(int i=2;i<=100000;i++)
        int cnt=0;
        double sum=0;
        for(int j=1;j*j<=i;j++)
            if(i%j==0)
                cnt++;
                sum+=dp[j];
                if(j*j!=i)
                    cnt++;
                    sum+=dp[i/j];
                
            
        
        dp[i]=(sum+cnt)/(cnt-1);
    


int main()

    Get_Dp();
    int _case,t=1;
    scanf("%d",&_case);
    while(_case--)
        scanf("%d",&n);
        printf("Case %d: %.10f\n",t++,dp[n]);
    
    return 0;

 

以上是关于loj 1038的主要内容,如果未能解决你的问题,请参考以下文章

PAT乙级1038

#1038 : 01背包

1038 Recover the Smallest Number (30 分)

GDUFE ACM-1038

1038 Recover the Smallest Number (30 分)

SQL 错误 (1038): 排序内存不足,请考虑增加服务器排序缓冲区