Breaking

Wednesday 4 October 2017

Collatz Sequence Sum

             Collatz Sequence Sum

The following iterative sequence is defined for the set of positive integers:
If at some point the value in the sequence is , we end the sequence at this point.
Using the rule above and starting with 13, we generate the following sequence:
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
Note: Once the chain starts the terms are allowed to go above .
Note: Just for the purpose of this problem, we define that the sequence starting at  has total length of .
Let  be the largest integer not greater than , which generates the longest Collatz sequence. The task is to find the sum .
This is an online problem. It means that the input is generated using the below generation method:
N[0] = 0
for i = 1 to T:
   N[i] = (A * N[i-1] + B) mod 5003
Input Format
In the first line, there are three space-separated integers .
Constraints
Output Format
Print the sum of results for all  tests.
Sample Input
3 1 4
Sample Output
19
Explanation
The generator generates 3 numbers:
.
.
.
Let  be the largest integer not greater than , which generates the longest sequence. Then, , and respective length of these longest sequences are  and . The result is the sum of numbers generating these longest sequences, so it's equal to .
Code:

coming soon..!
Please do comment If u have any Queries!

No comments:

Post a Comment

Like