Sequence Sum SOLUTION AtCoder Beginner Contest 179

Sequence Sum SOLUTION

Problem Statement
Let us signify by f ( x , m ) the rest of the Euclidean division of x by m . Let A be the arrangement that is characterized by the underlying worth A 1 = X furthermore, the repeat connection A n + 1 = f ( A 2 n ,
M ) . Find N ∑ I = 1 A I .
Imperatives
1 ≤ N ≤ 10
10
0 ≤ X < M ≤ 10
5
All qualities in input are numbers.
Info
Info is given from Standard Input in the accompanying configuration:
N X M
Yield
Print N ∑ I = 1 A I .
Test Input 1
Duplicate
6 2 1001
Test Output 1
Duplicate
1369
The succession
A
starts 2 , 4 , 16 , 256 , 471 , 620 , … Subsequently, the appropriate response is 2 + 4 + 16 + 256 + 471 + 620 = 1369 .
Test Input 2
Duplicate
1000 2 16
Test Output 2
Duplicate
6
The succession
A
starts 2 , 4 , 0 , 0 , … Subsequently, the appropriate response is 6 .
Test Input 3
Duplicate
10000000000 10 99959
Test Output 3
Duplicate
492443256176507

Leave a Comment

close
error: Content is protected !!