博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu5810——Balls and Boxes(数学推导)
阅读量:2344 次
发布时间:2019-05-10

本文共 1379 字,大约阅读时间需要 4 分钟。

Problem Description

Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner that each ball has equal probability of going to each boxes. After the experiment, he calculated the statistical variance V as
V=∑mi=1(Xi−X¯)2m

where Xi is the number of balls in the ith box, and X¯ is the average number of balls in a box.

Your task is to find out the expected value of V.

Input

The input contains multiple test cases. Each case contains two integers n and m (1 <= n, m <= 1000 000 000) in a line.
The input is terminated by n = m = 0.

Output

For each case, output the result as A/B in a line, where A/B should be an irreducible fraction. Let B=1 if the result is an integer.

Sample Input

2 1
2 2
0 0

Sample Output

0/1
1/2

反正最后推出来是n*(m-1)/m*m,恩

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 1010#define mod 1000000007using namespace std;long long gcd(long long a,long long b){ if(b==0) return a; else return gcd(b,a%b);}int main(){ long long a,b; while(~scanf("%I64d%I64d",&a,&b)) { if(a==0&&b==0) break; long long fz=a*(b-1); long long fm=b*b; long long c=gcd(fz,fm); if(fm==0) fm++; printf("%I64d/%I64d\n",fz/c,fm/c); } return 0;}

转载地址:http://fscvb.baihongyu.com/

你可能感兴趣的文章
rabbitmq安装
查看>>
RabbitMQ 使用
查看>>
动态代理
查看>>
oracle中merge into用法解析
查看>>
MySQL Explain详解
查看>>
oracle性能监控
查看>>
Spring Boot 整合Servlet
查看>>
Spring Boot 整合Filter
查看>>
nginx 安装
查看>>
ngnix 详解
查看>>
IDEA创建spring boot项目
查看>>
IDEA安装插件
查看>>
HttpClient-02连接管理
查看>>
数据库连接池-配置 wallfilter问题解决-UncategorizedSQLException
查看>>
java根据文件流判断文件类型(后缀名)
查看>>
js常用操作事件
查看>>
linux 安装mysql
查看>>
利用SQL语句查询数据库中所有表
查看>>
ActiveMQ 安装
查看>>
java可变参数
查看>>