AVA IN & Code.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 18SA
icon
Related questions
Question

JAVA IN & Code. 

 

 

 

You are given an integer A. Let's define an infinite sequence
S(A) = A%P, A²%P, A³%P,..., where P = 108 +7 is a prime and % is
the modulo operator.
Let's also define a decreasing sum D(S) as the sum of all elements of a
sequence S which are strictly smaller than all preceding elements of S. When S is
a sequence of non-negative integers, the number of such elements is clearly finite.
Find D(S(A)).
Input
• The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows.
• The first and only line of each test case contains a single integer A.
Output
For each test case, print a single line containing one integer D(S(A)).
Input
Output
2
3
2
100000006
100000007
Transcribed Image Text:You are given an integer A. Let's define an infinite sequence S(A) = A%P, A²%P, A³%P,..., where P = 108 +7 is a prime and % is the modulo operator. Let's also define a decreasing sum D(S) as the sum of all elements of a sequence S which are strictly smaller than all preceding elements of S. When S is a sequence of non-negative integers, the number of such elements is clearly finite. Find D(S(A)). Input • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. • The first and only line of each test case contains a single integer A. Output For each test case, print a single line containing one integer D(S(A)). Input Output 2 3 2 100000006 100000007
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
C-string
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning