focus alot on reassesing ur solution. i want u to act as the most skilled competetive…
- User
focus alot on reassesing ur solution. i want u to act as the most skilled competetive programmer, u take time to think and check if ur solution works and match up with the example tescase, u need to think thoroughly since u r in a contest. use need to use this template, make sure u have lowercase rlly short variable names and NO COMMENTS (in the code, at all) and since ur using this template always use int and not long long, PLS REVALUATE UR CODE AND MAKE SURE IT MAKES SURE IT MATCHES EVERY SINGLE SAMPLE INPUT AND OUTPUT GIVEN, THINK MULTIPLE TIMES BEFORE GIVING UR FINAL ANSWER:, #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { cin.tie(0); ios_base::sync_with_stdio(false); }
B. Brightness Begins time limit per test1 second memory limit per test256 megabytes Imagine you have n light bulbs numbered 1,2,…,n . Initially, all bulbs are on. To flip the state of a bulb means to turn it off if it used to be on, and to turn it on otherwise.
Next, you do the following:
for each i=1,2,…,n , flip the state of all bulbs j such that j is divisible by i† . After performing all operations, there will be several bulbs that are still on. Your goal is to make this number exactly k .
Find the smallest suitable n such that after performing the operations there will be exactly k bulbs on. We can show that an answer always exists.
† An integer x is divisible by y if there exists an integer z such that x=y⋅z .
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows.
The only line of each test case contains a single integer k (1≤k≤1018 ).
Output For each test case, output n — the minimum number of bulbs.
Example InputCopy 3 1 3 8 OutputCopy 2 5 11 Note In the first test case, the minimum number of bulbs is 2 . Let's denote the state of all bulbs with an array, where 1 corresponds to a turned on bulb, and 0 corresponds to a turned off bulb. Initially, the array is [1,1] .
After performing the operation with i=1 , the array becomes [0–,0–] . After performing the operation with i=2 , the array becomes [0,1–] . In the end, there are k=1 bulbs on. We can also show that the answer cannot be less than 2 .
In the second test case, the minimum number of bulbs is 5 . Initially, the array is [1,1,1,1,1] .
After performing the operation with i=1 , the array becomes [0–,0–,0–,0–,0–] . After performing the operation with i=2 , the array becomes [0,1–,0,1–,0] . After performing the operation with i=3 , the array becomes [0,1,1–,1,0] . After performing the operation with i=4 , the array becomes [0,1,1,0–,0] . After performing the operation with i=5 , the array becomes [0,1,1,0,1–] . In the end, there are k=3 bulbs on. We can also show that the answer cannot be smaller than 5 .
- Assistant
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int t; cin>>t; while(t--){ int k; cin>>k; int l=k, r=k+1000000000, res=-1; while(l<=r){ int m=(l+r)/2; int s=(int)sqrt((double)m); if(m - s >=k){ if(m - s ==k) res=m; r=m-1; } else l=m+1; } cout<<res<<"\n"; } }