Input Format The first line of input contains a positive integer T denoting the number of test cases that follow. Each test case is described in a single line containing a single integer N denoting the number of ice cream bars you have. Output Format For each test case, output a single line containing the number of days you can eat for before running out of ice cream bars and not being able to fully eat the next day. Constraints 1 s T ≤ 100 Main Test Set 1 ≤N≤ 105 Bonus Test Set 1 1 ≤N≤ 10¹5 Careful! If you are a Java or C/C++ programmer, be aware that the int variable type may be too small to contain N! Java programmers can use variable types long or float instead, and likewise long long or float for C/C++. Bonus Test Set 2 1sN≤ 1010000 Careful! Values of N in this test set are extremely large! They exceed the maximum values of 64 bit integers and floats. This one can be quite tricky to get right, so we recommend trying other problems first if you're stuck. Sample Test Cases Sample Input 0 1 2 3 6 11 69 1337 12345 Sample Explanations Sample Output 0 1 1 2 3 4 11 51 156 For test case 1, For test case 1, you have no ice cream bars. You can't eat any at all. Thus, you can only eat for 0 days. For test case 2, you have 1 ice cream bar. You eat your only bar on day 1, and then won't have enough for day 2. Thus, you can only eat for 1 days. For test case 3, you have 2 ice cream bars. You eat your first bar on day 1, and then won't have enough for day 2 because you need 2 but only have 1 more. Thus, you can only eat for 1 day. For test case 4, you have 3 ice cream bars. You eat your first bar on day 1, and then your last 2 bars on day 2. You won't have enough for day 3. Thus, you can eat for 2 days. For test case 5, you have 6 ice cream bars. You eat 1 bar on day 1, 2 bars on day 2, and 3 bars on day 3. You won't have enough for day 4. Thus, you can eat for 3 days. For test case 6, you have 11 ice cream bars. You eat 1 bar on day 1, 2 bars on day 2, 3 bars on day 3, and 4 bars on day 4. Since you only have 1 left, you won't have enough for day 5. Thus, you can eat for 4 days.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Solve this problem in Java. Use the provided template.

 

import java.io.*;

public class BarsTemplate {
/**
* Find and return the number of days you can eat for before running out
*
* N: the number of ice cream bars you have
*/
staticintsolve(intN) {
//your code here
return0;
}
 
staticBufferedReaderin = newBufferedReader(newInputStreamReader(System.in));
staticPrintWriterout = newPrintWriter(System.out);

publicstaticvoidmain(String[] args) throwsIOException {
intT = Integer.parseInt(in.readLine());
for (inti = 0; i < T; i++) {
intN = Integer.parseInt(in.readLine());
out.println(solve(N));
}
out.flush();
}
}
Introduction
Summer's finally here, and it's the perfect time to eat ice cream! For the past few months,
you've been saving a stash of delicious ice cream bars for this very moment! You decide to
come up with a plan to savor these tasty treats: on day 1, you eat 1 bar; on day 2, you eat 2
bars; on day 3, you eat 3 bars, and so on.
Oh, Haagen Dazs, if you wanna give us money, we're looking for sponsors ;)
Problem Statement
Given N bars of ice cream, find the number of days you can eat following your plan until you
run out and won't be able to eat the full amount planned for the next day.
On day 1, you eat 1 bar. On day 2, you eat 2 bars. On day 3, you eat 3 bars, and so on. In other
words, on day d, you eat d bars.
Transcribed Image Text:Introduction Summer's finally here, and it's the perfect time to eat ice cream! For the past few months, you've been saving a stash of delicious ice cream bars for this very moment! You decide to come up with a plan to savor these tasty treats: on day 1, you eat 1 bar; on day 2, you eat 2 bars; on day 3, you eat 3 bars, and so on. Oh, Haagen Dazs, if you wanna give us money, we're looking for sponsors ;) Problem Statement Given N bars of ice cream, find the number of days you can eat following your plan until you run out and won't be able to eat the full amount planned for the next day. On day 1, you eat 1 bar. On day 2, you eat 2 bars. On day 3, you eat 3 bars, and so on. In other words, on day d, you eat d bars.
Input Format
The first line of input contains a positive integer T denoting the number of test cases that
follow. Each test case is described in a single line containing a single integer N denoting the
number of ice cream bars you have.
Output Format
For each test case, output a single line containing the number of days you can eat for before
running out of ice cream bars and not being able to fully eat the next day.
Constraints
1 ≤ T ≤ 100
Main Test Set
1 ≤ N≤ 105
Bonus Test Set 1
1 ≤ N≤ 1015
Careful! If you are a Java or C/C++ programmer, be aware that the int variable type may be too
small to contain N! Java programmers can use variable types long or float instead, and likewise
long long or float for C/C++.
Bonus Test Set 2
1 ≤N≤ 1010000
Careful! Values of N in this test set are extremely large! They exceed the maximum values of 64
bit integers and floats. This one can be quite tricky to get right, so we recommend trying other
problems first if you're stuck.
Sample Test Cases
Sample Input
9
0
1
2
3
6
11
69
Sample Output
OHHN34
0
1
1
2
11
51
156
1337
12345
Sample Explanations
For test case 1, For test case 1, you have no ice cream bars. You can't eat any at all. Thus, you
can only eat for 0 days.
For test case 2, you have 1 ice cream bar. You eat your only bar on day 1, and then won't have
enough for day 2. Thus, you can only eat for 1 days.
For test case 3, you have 2 ice cream bars. You eat your first bar on day 1, and then won't have
enough for day 2 because you need 2 but only have 1 more. Thus, you can only eat for 1 day.
For test case 4, you have 3 ice cream bars. You eat your first bar on day 1, and then your last 2
bars on day 2. You won't have enough for day 3. Thus, you can eat for 2 days.
For test case 5, you have 6 ice cream bars. You eat 1 bar on day 1, 2 bars on day 2, and 3 bars
on day 3. You won't have enough for day 4. Thus, you can eat for 3 days.
For test case 6, you have 11 ice cream bars. You eat 1 bar on day 1, 2 bars on day 2, 3 bars on
day 3, and 4 bars on day 4. Since you only have 1 left, you won't have enough for day 5. Thus,
you can eat for 4 days.
Transcribed Image Text:Input Format The first line of input contains a positive integer T denoting the number of test cases that follow. Each test case is described in a single line containing a single integer N denoting the number of ice cream bars you have. Output Format For each test case, output a single line containing the number of days you can eat for before running out of ice cream bars and not being able to fully eat the next day. Constraints 1 ≤ T ≤ 100 Main Test Set 1 ≤ N≤ 105 Bonus Test Set 1 1 ≤ N≤ 1015 Careful! If you are a Java or C/C++ programmer, be aware that the int variable type may be too small to contain N! Java programmers can use variable types long or float instead, and likewise long long or float for C/C++. Bonus Test Set 2 1 ≤N≤ 1010000 Careful! Values of N in this test set are extremely large! They exceed the maximum values of 64 bit integers and floats. This one can be quite tricky to get right, so we recommend trying other problems first if you're stuck. Sample Test Cases Sample Input 9 0 1 2 3 6 11 69 Sample Output OHHN34 0 1 1 2 11 51 156 1337 12345 Sample Explanations For test case 1, For test case 1, you have no ice cream bars. You can't eat any at all. Thus, you can only eat for 0 days. For test case 2, you have 1 ice cream bar. You eat your only bar on day 1, and then won't have enough for day 2. Thus, you can only eat for 1 days. For test case 3, you have 2 ice cream bars. You eat your first bar on day 1, and then won't have enough for day 2 because you need 2 but only have 1 more. Thus, you can only eat for 1 day. For test case 4, you have 3 ice cream bars. You eat your first bar on day 1, and then your last 2 bars on day 2. You won't have enough for day 3. Thus, you can eat for 2 days. For test case 5, you have 6 ice cream bars. You eat 1 bar on day 1, 2 bars on day 2, and 3 bars on day 3. You won't have enough for day 4. Thus, you can eat for 3 days. For test case 6, you have 11 ice cream bars. You eat 1 bar on day 1, 2 bars on day 2, 3 bars on day 3, and 4 bars on day 4. Since you only have 1 left, you won't have enough for day 5. Thus, you can eat for 4 days.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education