Page 1 of 1

Alex book Alex has a book of an infinite number of pages. Imagine practically when a book is opened 2 pages get opened 1

Posted: Mon May 09, 2022 7:15 am
by answerhappygod
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 1
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 1 (304.23 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 2
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 2 (235.14 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 3
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 3 (185.02 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 4
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 4 (264.04 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 5
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 5 (247.3 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 6
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 6 (213.25 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 7
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 7 (131.66 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 8
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 8 (133.99 KiB) Viewed 107 times
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 9
Alex Book Alex Has A Book Of An Infinite Number Of Pages Imagine Practically When A Book Is Opened 2 Pages Get Opened 1 9 (148.89 KiB) Viewed 107 times
I want code in java script node.js 16.4 only
don't modify solution
Alex book Alex has a book of an infinite number of pages. Imagine practically when a book is opened 2 pages get opened 1 on left and 1 on the right side except starting page which doesn't have any page to its left. In an open book left and right page numbers which open together form a spread. 1st page doesn't have any page to its left so page number 1 itself forms a spread and further all spreads have 2-page numbers in them. The first spread contains page 1, the second spread contains pages 2 and 3, the third spread contains pages 4 and 5 and the fourth spread contains pages 6 and 7 and soon. Task Determine the first-page number of the very first spread where the sum of the digits of page numbers is S. If no such spread exists, print -1. Note: Page number 1 itself forms a spread and thus is the first page for the first spread. Example
the first spread Example Assumption • S= 9 Approach • The first spread contains page 1 only. the sum of digits of page number is 1. • The second spread contains pages 2 and 3. the sum of digits of page numbers is 5(2+3). • The third spread contains pages 4 and 5. the sum of digits of page numbers is 9(4-5). +/ So the third spread is the pst spread whose sum of digits of page numbers is 9. Thus, the answer is 4. Function description Complete the function solve provided in the editor. This function takes the following parameters and returns the required answer: 2 S. Renracon
Function description Complete the function solve provided in the editor. This function takes the following parameters and returns the required answer: • S: Represents the required sum Input format Note: This is the input format that you must use to provide custom input (available above the Compile and Test button). • The first line contains T denoting the number of test cases. T also specifies the number of times you have to run the solve function on a different set of inputs. For each test case: +/- o The first line contains S denoting the required sum. Output format For each test case, print the answer in a new line. 3 Constraints 11 1ST < 103 12 15 N <105 12
1ST < 103 1<N< 105 Code snippets (also called starter code/boilerplate code) This question has code snippets for C, CPP, Java, and Python. Sample input Sample output B 1 16 15 2 5
Explanation The first line contains the number of test cases. T = 3 The first test case Given S = 1 Approach • The first spread contains page 1 whose sum of digits is 1 Thus, the answer is "1"! The second test case Given • S = 15 Approach Spread containing page numbers 16. 17 is the first spread having a sum of digits of its page numbers as 15 (1+6+7+7). Thus, the answer is 16 The third test case Given 5
The third test case Given • S = 5 Approach . The second spread contains pages 2, 3. whose sum of digits of page numbers is 5 Thus the answer is 2. The following test cases are the actual test cases of this question that may be used to evaluate your submission. Sample input 1 > E Sample output 1 5 38 23 598 45 8999998 123 598 45 99998 89
process.stdin.resume(); 2 process.stdin.setEncoding('utf-8'); 3 var input 5 6 process.stdin.on('data', function (data) { 7 input += data.tostring().trim(); 8 input_ += '\n'; 9 10 11 E function solve($) { 12 3 // You must complete the logic for the function that is provided 13 // before compiling or submitting to avoid an error. 14 I // Write your code here 16 17 } 18 19 process.stdin.on('end', function () { 20 input_ = input_.replace(/\n$/,""); 21 input_ = input_.split("\n"); 15 =
your code here 16 17 } 18 19 e process.stdin.on('end', function () { 20 input input_.replace(/\n$/,""); 21 input = input_.split("\n"); 11 = 22 23 - 24 var idx_ = 0; var T = parseInt(input_[idx_++].trim(), 10); for(var t_i = 0; t_i< T; t_i++) { var s = parseInt(input_[idx_++].trim(), 10); S 25 E = 26 27 28 29 var out_ = solve( s); process.stdout.write(out_.tostring()); process.stdout.write('\n'); 30 31 } 32 33 process.exit(); 21
18 19 E process.stdin.on('end', function () { input input_.replace(/\n$/,""); input_ = input_.split("\n"); 20 21 22 23 24 var idx_ = 0; var T = parseInt(input_[idx_++].trim(), 10); for(var t_i = 0; t_i < T; t_i++) { var s = parseInt(input_[idx_++].trim(), 10); ) 25 26 S = 27 28 29 var out solve( s); process.stdout.write(out_.toString()); process.stdout.write('\n'); 30 I 31 } 32 33 process.exit(); 34 35 });