题目

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. idea中怎么去查看maven项目的依赖包是否有冲突

    1:快捷键:

  2. Linux基本服务

    一.Samba服务 1.下载samba yum install samba -y 2.配置samba文件 vim /etc/samba/smb.conf [ken]path = /test    #等 ...

  3. Centos7安装protobuf3.6.1

    简介 最近学习go语言,需要安装protobuf,但是网上的教程很多都不太适用于centos7 的系统.现在总结下protobuf在centos7下的安装教程. protobuf是Google开发出来 ...

  4. 安装mysql5.6-centOs7

    安装mysql mysql,下载地址:https://dev.mysql.com/downloads/mysql/ 安装参考链接:https://segmentfault.com/a/11900000 ...

  5. “EndExecuteNonQuery”方法没有任何重载采用“0”个参数

    EndExecuteNonQuery需要参数IAsyncResult asyncResult myCmd.ExecuteNonQuery();//执行 ExecuteNonQuery 返回受影响行数

  6. [转帖]探秘华为(一):华为和H3C(华三)的爱恨情仇史!

    探秘华为(一):华为和H3C(华三)的爱恨情仇史! https://baijiahao.baidu.com/s?id=1620703498823290828&wfr=spider&fo ...

  7. Java8---函数式编程-示例

    // Java8函数式编程示例—(Predicate.Stream.Optional) https://blog.csdn.net/weixin_41950473/article/details/84 ...

  8. [Bzoj1597][Usaco2008 Mar]土地购买(斜率优化)

    题目链接 因为题目说可以分组,并且是求最值,所以斜率优化应该是可以搞的,现在要想怎么排序使得相邻的数在一个组中最优. 我们按照宽$w$从小到大,高$h$从小到大排序.这时发现可以筛掉一些一定没有贡献的 ...

  9. osi七层模型??

    1.应用层:提供用户服务,例如处理应用程序,文件传输,数据管理      (HTTP.RTSP.FTP) 2.表示层:做数据的转换和压缩,加解密等 3.会话层:决定了进程间的连接建立,选择使用什么样的 ...

  10. Kibana 基本操作

    es中的索引对应mysql的数据库.类型对应mysql的表.文档对应mysql的记录.映射对应mysql的索引索引:index类型:type映射:mappings 1.创建索引在kibana的Dev ...