程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> numbers-Recamans Sequence

numbers-Recamans Sequence

編輯:編程解疑
Recaman's Sequence

Description

The Recaman’s sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already in the sequence, otherwise am = am−1 + m.
The first few numbers in the Recaman’s Sequence is 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9 …
Given k, your task is to calculate ak.
Input

The input consists of several test cases. Each line of the input contains an integer k where 0 <= k <= 500000.
The last line contains an integer −1, which should not be processed.
Output

For each k given in the input, print one line containing ak to the output.
Sample Input

7
10000
-1
Sample Output

20
18658

最佳回答:


http://blog.csdn.net/dacc123/article/details/50478567

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved