JAVA_CODE.

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter2: Basic Linear Algebra
Section: Chapter Questions
Problem 15RP
icon
Related questions
Question

JAVA_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 3 steps with 1 images

Blurred answer
Knowledge Booster
Fundamentals of JavaScript
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
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
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
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning