题目

Rimi 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

大意

给出一个数,每次随机处一个它的因子,求他变成1的期望次数。

题解

令 f[I] 表示i在f[i]此后变成1。

\[f[i] = \sum_{j|i} (f[j]+1) / k, (k = \sum_j [j|i])
\]

代码

#include<bits/stdc++.h>
#define repeat(a,b,c,g) for (int a=b,abck=(g>=0?1:-1);abck*(a)<=abck*(c);a+=g)
using namespace std;
double f[110000];
int main()
{
f[1] = 0;
for (int i=2;i<=100000;i++)
{
double tot = 0;
int tp = -1;
for (int j=1;j<=sqrt(i);j++)
{
if (i % j == 0)
{
tp ++, tot += f[j] + 1;
if (j * j != i)
tp ++, tot += f[i/j] + 1;
}
}
f[i] = tot / tp;
}
int n;
cin >> n;
for (int i=1;i<=n;i++)
{
int tmp;
cin >> tmp;
printf("Case %d: %.7f\n",i,f[tmp]);
}
}

A - Race to 1 Again的更多相关文章

  1. Promise.race

    [Promise.race] 返回最先完成的promise var p1 = new Promise(function(resolve, reject) { setTimeout(resolve, 5 ...

  2. golang中的race检测

    golang中的race检测 由于golang中的go是非常方便的,加上函数又非常容易隐藏go. 所以很多时候,当我们写出一个程序的时候,我们并不知道这个程序在并发情况下会不会出现什么问题. 所以在本 ...

  3. 【BZOJ-2599】Race 点分治

    2599: [IOI2011]Race Time Limit: 70 Sec  Memory Limit: 128 MBSubmit: 2590  Solved: 769[Submit][Status ...

  4. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  5. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  6. 【多线程同步案例】Race Condition引起的性能问题

    Race Condition(也叫做资源竞争),是多线程编程中比较头疼的问题.特别是Java多线程模型当中,经常会因为多个线程同时访问相同的共享数据,而造成数据的不一致性.为了解决这个问题,通常来说需 ...

  7. Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm

    C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/probl ...

  8. HDU 4123 Bob’s Race 树的直径 RMQ

    Bob’s Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=41 ...

  9. [LOJ 1038] Race to 1 Again

    C - Race to 1 Again Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu D ...

  10. 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)

    Walking Race   Description flymouse's sister wc is very capable at sports and her favorite event is ...

随机推荐

  1. 【Linux开发】【DSP开发】利用CCS6.1生成out文件的同时生成bin文件

    [Linux开发][DSP开发]利用CCS6.1生成out文件的同时生成bin文件 标签:[DSP开发] [Linux开发] 尝试在windows上安装的CCS6.1开发AM4378-Linux下的应 ...

  2. 国家授时中心的NTP服务器地址 210.72.145.44

    国家授时中心的NTP服务器地址 210.72.145.44

  3. PHPFPM模式三种运行模式

    1.static模式 static模式始终会保持一个固定数量的子进程,这个数量由pm.max_children定义.   2.dynamic模式 子进程的数量是动态变化的,启动时,会生成固定数量的子进 ...

  4. Bean与Map的转换 和 Map与Bean的转换

    package com.JUtils.beanConvert; import java.beans.BeanInfo; import java.beans.IntrospectionException ...

  5. Java基础语法—数据输入

    我们可以通过 Scanner 类来获取用户的输入.使用步骤如下: 1.导包.Scanner 类在java.util包下,所以需要将该类导入.导包的语句需要定义在类的上面. import java.ut ...

  6. laravel框架源码分析(一)自动加载

    一.前言 使用php已有好几年,laravel的使用也是有好长时间,但是一直对于框架源码的理解不深,原因很多,归根到底还是php基础不扎实,所以源码看起来也比较吃力.最近有时间,所以开启第5.6遍的框 ...

  7. 【Linux-驱动】驱动策略----自旋锁

    自旋锁 自旋锁最多只能被一个内核任务持有.要是锁未被持有,请求它的内核任务便会立即得到它并继续执行.如果一个内核任务试图请求一个已经被别的内核任务持有的自旋锁,那么CPU就会一直尽心循环---旋转-- ...

  8. Charles的app抓包配置和抓包节点为unknown、乱码、手机无法上网等问题的处理

    关于手机端抓包配置Charles的一些配置,并且解决,请求存在unknown和内容为乱码的问题 关于请求节点为unknown.内容为乱码和手机端无法访问网络其实都是手机端证书配置问题导致,有的配置后还 ...

  9. Thinkphp设置PC和手机端模板

    <?php // 判断手机端 function ismobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X ...

  10. [LeetCode] 210. 课程表 II

    题目链接:https://leetcode-cn.com/problems/course-schedule-ii/ 题目描述: 现在你总共有 n 门课需要选,记为 0 到 n-1. 在选修某些课程之前 ...