cf Vasily the Bear and Fly

本博客介绍了一个有趣的数学问题:熊Vasily通过画圆来引导一只苍蝇在坐标平面上飞行,并计算苍蝇在m²天内平均飞行的距离。通过输入熊画的圆的数量m和圆的半径R,读者可以学习如何解决这个问题并计算出答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. Vasily the Bear and Fly
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One beautiful day Vasily the bear painted 2m circles of the same radius R on a coordinate plane. Circles with numbers from 1 to m had centers at points (2R - R, 0)(4R - R, 0)...(2Rm - R, 0), respectively. Circles with numbers from m + 1 to 2m had centers at points(2R - R, 2R)(4R - R, 2R)...(2Rm - R, 2R), respectively.

Naturally, the bear painted the circles for a simple experiment with a fly. The experiment continued for m2 days. Each day of the experiment got its own unique number from 0 to m2 - 1, inclusive.

On the day number i the following things happened:

  1. The fly arrived at the coordinate plane at the center of the circle with number  ( is the result of dividing number xby number y, rounded down to an integer).
  2. The fly went along the coordinate plane to the center of the circle number  ( is the remainder after dividing number x by number y). The bear noticed that the fly went from the center of circle v to the center of circle ualong the shortest path with all points lying on the border or inside at least one of the 2m circles. After the fly reached the center of circle u, it flew away in an unknown direction.

Help Vasily, count the average distance the fly went along the coordinate plane during each of these m2 days.

Input

The first line contains two integers m, R (1 ≤ m ≤ 1051 ≤ R ≤ 10).

Output

In a single line print a single real number — the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.

Sample test(s)
input
1 1
output
2.0000000000
input
2 2
output
5.4142135624
Note

Figure to the second sample



#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
double f[2];
int main()
{
    int m,r,i,t;
    double addv;

    while(~scanf("%d%d",&m,&r))
    {
        addv=sqrt(2.0)*r;
        t=0;
        f[t]=2*r;
        for(i=2;i<=m;i++)
            {
                f[t^1]=f[t]+2*r+2*(2*r+(2*i-3)*addv+(__int64)(i-1)*(i-2)*r);
                t^=1;
            }
        printf("%.10lf\n",f[t]/((__int64)m*m));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值