We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #26: Reciprocal cycles
Project Euler #26: Reciprocal cycles
Contest ends in
Sort by
recency
|
39 Discussions
|
Please Login in order to post a comment
// c# using System;
public class Program { static int FindCycle(int n) { int[] seen = new int[n]; seen[1] = 1; int m = 1; int i = 2;
}
100% divide will calculate the reccurance , by long division method by dividing 100* > n
Explanation for this simple problem:
recurring_digits function: This function calculates the span of recurring digits in the decimal expansion of 1/n. It first removes factors of 2 and 5, then iteratively multiplies the remainder by 10 and takes the remainder after division by n until a recurring cycle is detected.
answers list: list is used to store the maximum recurring digit numbers for each index. It is initialized with four zeros, and the code iterates through numbers from 3 to 10^4 to populate this list.
Loop for finding maximum recurring digit numbers: The loop iterates through numbers from 3 to 10^4, calculates the recurring digits for each number using the recurring_digits function, and updates the maximum recurring digit number and count accordingly.
User input processing: The code then takes user input for the number of test cases and the specific values for which it needs to find the maximum recurring digit numbers. It prints the results accordingly.
Probably rare reason for test Case 1 failure:
Test case 1 failed because I simply got it wrong, long division method: I checked whether the remainder has already been seen before expanding the remainder it out with extra zeros. Thus for example if the remainder is 9 in one instance, and 90 in the next, this would not get flagged as the same and the start of a recurrence, even though it should be.