Light OJ 1038 Race to 1 Again (probabilistic DP)

Source: Internet
Author: User

1038-race to 1 Again
PDF (中文版) Statistics Forum
Time Limit: 2 second (s) Memory Limit: MB

Rimi learned a new thing about integers, which is-any positive integer greater than 1 can is divided by its div Isors. So, he's now playing with the This property. He selects a number N. And he calls thisD.

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's 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 is begins with an integer N (1≤n≤105).

Output

For each case, the input you has to print the case number and the expected value. Errors less than 10-6 'll be ignored.

Sample Input Output for Sample Input

3

1

2

50

Case 1:0

Case 2:2

Case 3:3.0333333333

Problem Setter:jane ALAM JAN

Set x has n factors, dp[x] = (Dp[i]+dp[j]+....+dp[k]) * (1/n) +dp[n]*1/n+1; (I,j,k = factor of X)

Change it to get dp[x] expression,



#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8//typedef __ Int64 ll; #define FRE (i,a,b) for (i = A; I <b; i++) #define FREE (i,b,a) for (i = b; I >= a;i--) #define MEM (T, v) MEMS ET ((t), V, sizeof (t)) #define SSF (n) scanf ("%s", N) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf (          "%d%d", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF Printf#define Bug PF ("hi\n") using namespace std; #define INF 0x3f3f3f3f#define n 100005double dp[n];int n;void inint () {int i,j,cnt;d   Ouble Temp;dp[1]=0;mem (dp,0); Fre (i,2,n) {cnt=0;  Temp=0;   for (j=1;j*j<=i;j++) if (i%j==0) {cnt++;   TEMP+=DP[J];   if (j*j!=i) {temp+=dp[i/j]; cnt++;} } dp[i]= (TeMP+CNT)/(CNT-1);  }}int Main () {int i,j,t,ca=0;sf (t), Inint (), while (t--) {SF (n);p f ("Case%d:%.6lf\n", ++ca,dp[n]);} return 0;}



Light OJ 1038 Race to 1 Again (probabilistic 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.