There is a well-known formula for the sum $$$f(n)$$$ of the first $$$n$$$ squares, $$$$$$f(n) = 1^2 + 2^2 + 3^2 + \ldots + n^2 = \frac{n(n+1)(2n+1)}{6}.$$$$$$
Write a function that computes $$$n$$$ given $$$f(n)$$$.
The first line of input contains a single integer $$$T$$$, the number of test cases $$$(1 \leq T \leq 10\,000)$$$. Each of the following $$$T$$$ lines contain a single integer $$$k$$$ $$$(1 \leq k \leq 2^{60})$$$.
For each test case, print a line with the positive integer $$$n$$$ satisfying $$$f(n) = k$$$. It is guaranteed that such an integer exists.
515143851152919708258615990
1 2 3 10 1512307
Hint: the largest possible value of $$$n$$$ with $$$f(n) \leq 2^{60}$$$ is $$$n=1512307$$$.
You have been hired by the Texas Exes to build an app that helps Longhorns fans track the performance of the football team over time. One of the features they've requested is for the user to select a range of historical games; the app should then tell them whether or not the Longhorns had a winning record within that range of games.
Write an algorithm that implements this feature.
The first line of input contains two integers $$$n$$$ and $$$k$$$ $$$(1 \leq n, k \leq 100\,000)$$$: the number of games in the database and the number of ranges that you need to analyze.
The next line is a string of exactly $$$n$$$ characters. Each character is either W or L, indicating that the Longhorns won or lost the game. The wins and losses are listed in chronological order from oldest game to newest.
The final $$$k$$$ lines are ranges to analyze. Each range contains two space-separated integers $$$i$$$ and $$$j$$$ $$$(1 \leq i \leq j \leq n)$$$.
Print a string of $$$k$$$ characters, representing the results of your analysis for each of the $$$k$$$ ranges (in order).
For each range, print a Y if the Longhorns won more games than they lost between games $$$i$$$ and $$$j$$$ inclusive. Otherwise, print N.
(Note in particular that if the Longhorns won and lost the same number of games in a range, you should print N.)
11 5WWLWLWLLLWW1 11 36 112 61 11
YYNYY
You've been tasked with buying fruit to put in snack trays at your student org's annual kickoff event. You know you will need at least $$$P$$$ total pounds of fruit, so you've taken a shopping trip to HEB.
Fruit at HEB is priced in dollars per pound, and HEB only has a limited amount of each type of fruit in stock. What is the cheapest price you must pay to buy $$$P$$$ total pounds of fruit, given your options?
Although not completely realistic, for the purposes of this problem you may assume that if HEB stocks $$$k$$$ pounds of a fruit, it is possible to buy any amount of that fruit between $$$0$$$ and $$$k$$$ pounds.
The first line of input contains two space-separated integers $$$P$$$ and $$$n$$$: the total pounds of fruit you need to buy $$$(1 \leq P \leq 1\,000)$$$, and the number of types of fruit sold at HEB $$$(1 \leq n \leq 100)$$$. The next $$$n$$$ lines describe the fruit on offer. Each line contains a real number $$$p$$$, the price of the fruit in dollars per pound $$$(0.01 \leq p \leq 100.00)$$$, and an integer $$$k$$$, the total pounds of that fruit that HEB has in stock $$$(1 \leq k \leq 100)$$$.
If it is impossible to buy $$$P$$$ pounds of fruit given the options in stock, print -1.
Otherwise, print the cheapest price (in dollars) you must pay to purchase $$$P$$$ pounds of fruit. Your answer will be judged correct if it matches the judge solution with relative or absolute error at most $$$10^{-4}$$$.
100 31.75 532.01 201.06 41
148.27
50 22.00 203.50 20
-1
Congratulations! You've been selected by Conglomo Corp. as a finalist for a summer internship. They are flying you to their headquarters for a final in-person interview.
Some flights are more likely to arrive on time than others, and you want to maximize the probability that you arrive at the interview on time and without missing a connection. Nothing else matters: you are willing to take a longer overall trip with more flight segments if doing so has a higher chance of arriving on time than a shorter itinerary.
Given a list of flights, each of which has a starting city, ending city, and probability of arriving on time, compute the optimal itinerary for arriving at the interview without incident.
The first line of input contains two space-separated integers $$$n$$$ ($$$2 \leq n \leq 50\,000$$$) and $$$m$$$ ($$$1 \leq m \leq 50\,000$$$): the number of cities the airline serves, and the number of available flights, respectively.
Each of the next $$$m$$$ lines describes one flight. A flight consists of two space-separated integers $$$s$$$ and $$$d$$$ followed by a real number $$$p$$$ ($$$1 \leq s,d \leq n$$$, $$$0.0 \leq p \leq 1.0$$$), indicating that a flight exists from city $$$s$$$ to city $$$d$$$, and that this flight arrives on time with probability $$$p$$$. All listed flights are one-way and it is guaranteed that $$$s \neq d$$$. There might be multiple flights with the same source and destination city.
City $$$1$$$ is Austin and city $$$n$$$ is Conglomo Corp. headquarters.
Print the probability of arriving at your job interview on time, assuming you fly using the optimal itinerary that maximizes this probability. Your answer will be judged correct if it differs from the judge answer with relative or absolute error at most $$$10^{-4}$$$.
Assume that flight delays are independent events, so that the probability of arriving at Conglomo Corp. headquarters is the product of the probabilities that all flights along the way arrive on time.
Note that if it is impossible to travel from Austin to Conglomo Corp. headquarters, the probability of arriving on time is $$$0$$$.
3 61 3 0.21 2 0.91 2 0.82 3 0.73 1 1.03 2 0.9
0.630000000000000004440892098501
4 51 2 0.51 3 1.02 3 0.93 2 1.04 1 1.0
0.0