Code Signal_练习题_Circle of Numbers

圆周数对求解
本文介绍了一种解决特定数学问题的方法:在一个等间距排列的圆周上找到与给定数字径向相对的位置上的数字。该算法适用于整数范围从0到n-1,且能快速准确地给出答案。

Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1are neighboring, too).

Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber.

Example

For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.

 

我的解答:

def circleOfNumbers(n, firstNumber):
    return (firstNumber+n/2) % n

 

我的解法和排名第一的大佬写的一样....哈哈哈
膜拜大佬

 

转载于:https://www.cnblogs.com/BlameKidd/p/9471656.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值