A - Race to 1 Again
题目
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。
\]
代码
#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的更多相关文章
- Promise.race
[Promise.race] 返回最先完成的promise var p1 = new Promise(function(resolve, reject) { setTimeout(resolve, 5 ...
- golang中的race检测
golang中的race检测 由于golang中的go是非常方便的,加上函数又非常容易隐藏go. 所以很多时候,当我们写出一个程序的时候,我们并不知道这个程序在并发情况下会不会出现什么问题. 所以在本 ...
- 【BZOJ-2599】Race 点分治
2599: [IOI2011]Race Time Limit: 70 Sec Memory Limit: 128 MBSubmit: 2590 Solved: 769[Submit][Status ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #131 (Div. 2) E. Relay Race dp
题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...
- 【多线程同步案例】Race Condition引起的性能问题
Race Condition(也叫做资源竞争),是多线程编程中比较头疼的问题.特别是Java多线程模型当中,经常会因为多个线程同时访问相同的共享数据,而造成数据的不一致性.为了解决这个问题,通常来说需 ...
- 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 ...
- 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 ...
- [LOJ 1038] Race to 1 Again
C - Race to 1 Again Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu D ...
- 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)
Walking Race Description flymouse's sister wc is very capable at sports and her favorite event is ...
随机推荐
- 操作系统(3)实验相关原理——bootloader启动uCore
x86启动顺序 CS+EIP决定启动地址. CS部分后面又4个0,相当于是左移了4位.总之就是要让CS左移4位之后加上EIP来得到要跳转的地址. 0x7c00地方开始的512字节的内容就是bootlo ...
- anaconda3,将python版本回退(python3.7---python3.5)
2019/6 安装anaconda3时,安装了默认的最新版本,但是由于不能兼容tensorflow,我又配置了一个python3.5的环境: 可惜这里真的不晓得咋回事,在python3.5中进入jup ...
- clearfix:after 的用法
想要清除浮动就要在父元素上 加上 clearfix:after .clearfix:after { <----在类名为“clearfix”的元素内最后面加入内容: content: " ...
- express中app.use()使用方法
app.use([path,] function [, function…]) 在path上安装中间件,如果path没有被设定,那么默认为”/”. 当为路由设置一个匹配路径后,路由会匹配该路径及该路径 ...
- [JS] 鼠标点击文本框清空默认值,离开文本框恢复默认值
在使用文本框的时候,若设定了初始值,选择文本框进行输入的时候要将本来的内容进行删除,会显得非常麻烦 可以在文本框属性定义触发onfocus和onblur两个事件时对应的js功能 下面以asp.net代 ...
- 第四周Java作业及总结
写一个名为Rectangle的类表示矩形.其属性包括宽width.高height和颜色color,width和height都是double型的,而color则是String类型的.要求该类具有: (1 ...
- Dubbo原理学习
Dubbo源码及原理学习 阿里中间件团队博客 Dubbo官网 Dubbo源码解析 Dubbo源码解析-掘金 Dubbo源码解析-赵计刚 Dubbo系列 源码总结+最近感悟
- SwipeRefreshLayout和RecyclerView类
1 SwipeRefreshLayout和RecyclerView之间的关系 内容栏上下滚动是RecyclerView控制的,只有当内容栏滑动到最顶上时,再也拉不动了的时候,这个时候将动作交给Swip ...
- 介绍一下 except 的作用和用法?
except: #捕获所有异常 except: <异常名>: #捕获指定异常 except:<异常名 1, 异常名 2> : 捕获异常 1 或者异常 2 except:< ...
- win10常用的dos命令
1.calc:启动计算器 2.appwiz.cpl:程序和功能 3.certmgr.msc:证书管理实用程序 4.charmap:启动字符映射表 5.chkdsk.exe:Chkdsk磁盘检查(管理员 ...