Square root digital expansion It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all. The square root of two i…
from decimal import getcontext, Decimal def main(): n = int(raw_input()) p = int(raw_input()) getcontext().prec = p+10 # 扩大精度,保证接过 sum = 0 for i in range(1,n+1): nTemp = Decimal(i).sqrt() if nTemp._isinteger() : # 自生函数的判断 sum += 0 else: nTemp = str(n…
五十七.平方根收敛(Square root convergents) 二的平方根可以表示为以下这个无穷连分数: \[ \sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac 1 {2+ \dots}}} \] 通过把前四项展开,我们得到: \[ \begin{aligned}1 + \frac 1 2 &= \frac 32 = 1.5\\1 + \frac 1 {2 + \frac 1 2} &= \frac 7 5 = 1.4\\1 + \frac 1 {2…
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest product in a grid # In the 20×20 grid below, four numbers along a diagonal line have been marked in red. # The product of these numbers is 26 × 63 × 78 ×…
A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44 → 32 → 13 → 10 → 1 → 1 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89 Therefore any chain that…
Cube digit pairs Each of the six faces on a cube has a different digit (0 to 9) written on it; the same is done to a second cube. By placing the two cubes side-by-side in different positions we can form a variety of 2-digit numbers. For example, the…
It is possible to show that the square root of two can be expressed as an infinite continued fraction.  2 = 1 + 1/(2 + 1/(2 + 1/(2 + ... ))) = 1.414213... By expanding this for the first four iterations, we get: 1 + 1/2 = 3/2 = 1.51 + 1/(2 + 1/2) = 7…
计算机上的每个字母都对应一个独特的编号,普遍接受的标准是ASCII(美国信息交换标准代码).例如,大写字母的A的ASCII码是65,星号(*)的ASCII码是42,而小写字母k的代码是107. 一种现代的加密方法是:输入一个文本文件,把其中的字节转化为对应的ASCII码,然后用从秘钥中获得的特定值和每个字节做异或运算.异或函数的一个好处是对密文使用同样的密钥就可以还原出明文,比如\(65\ XOR\ 42=107\),同时\(107\ XOR\ 42=65\). 如果密钥的长度和明文的长度一样长…
A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) an…
本题来自 Project Euler 第6题:https://projecteuler.net/problem=6 # Project Euler: Problem 6: Sum square difference # The sum of the squares of the first ten natural numbers is, # 1**2 + 2**2 + ... + 10**2 = 385 # The square of the sum of the first ten natur…