freeCodeCamp/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-26-reciprocal-cycle...

1.9 KiB
Raw Blame History

id challengeType videoUrl title
5900f3861000cf542c50fe99 5 问题26互惠周期

Description

单位分数在分子中包含1。给出分母2到10的单位分数的十进制表示
二分之一 = 0.5
三分之一 = 03
四分之一 = 0.25
1/5 = 0.2
六分之一 = 0.16
七分之一 = 0142857
八分之一 = 0.125
九分之一 = 01
一十分之一 = 0.1
其中0.16表示0.166666 ...并具有1位循环周期。可以看出 1 / 7具有6位循环周期。找到d < n的值,其中1 / d包含其小数部分中最长的循环周期。

Instructions

Tests

tests:
  - text: <code>reciprocalCycles(700)</code>应该返回659。
    testString: assert(reciprocalCycles(700) == 659);
  - text: <code>reciprocalCycles(800)</code>应该返回743。
    testString: assert(reciprocalCycles(800) == 743);
  - text: <code>reciprocalCycles(900)</code>应该返回887。
    testString: assert(reciprocalCycles(900) == 887);
  - text: <code>reciprocalCycles(1000)</code>应该返回983。
    testString: assert(reciprocalCycles(1000) == 983);

Challenge Seed

function reciprocalCycles(n) {
  // Good luck!
  return n;
}

reciprocalCycles(1000);

Solution

// solution required

/section>