当前位置:网站首页>Niuke monthly race 31 minus integer
Niuke monthly race 31 minus integer
2022-07-03 18:13:00 【Lovely and beautiful girl】
The question :
Just give you a number n, Then subtract... In turn 1,2,3,… If it happens to be reduced to 0 Quit , If not enough, add n, from 1 Begin to reduce , I asked you how many times to repeat it, plus n This operation . Of course, it's an operation at the beginning . If there is no solution, output impossible.
reflection :
At first, I felt like a direct simulation after reading this topic , See when you can quit at least , But it will definitely jam you . Then I feel that there is no solution , In fact, after careful consideration . When we reduce to b, Now there are still a,a Not enough to reduce b Then add n, After this operation, the rest will become 2a,3a…, So now is to ask you , How many? a-b==0. This is not obvious , Because it doesn't have to be added b This number , In fact, in the process of subtraction . As long as we reach xa%b==0 It must be equal to 0 了 . So it's asking for a and b The least common multiple of , Then divide by a, See how many you want a That's enough .
In fact, this topic , For the number of operations , Often take the HKCEE gcd The nature of the matter .
Code :
int T,n,m,k;
int va[N];
signed main()
{
IOS;
cin>>T;
while(T--)
{
cin>>n;
int l = 1,r = n;
while(l<r)
{
int mid = l+r+1>>1;
if(mid*(mid+1)/2<=n) l = mid;
else r = mid-1;
}
int a = n-l*(l+1)/2,b = l+1;
if(a==0) // Pay attention to the special judgment here , Otherwise, division appears below 0 The situation of .
{
cout<<1<<"\n";
continue;
}
int now = a*b/__gcd(a,b)/a;
cout<<now<<"\n";
}
return 0;
}
summary :
Accumulate more experience .
边栏推荐
- A. Berland Poker &1000【简单数学思维】
- [combinatorics] generating function (example of using generating function to solve the number of solutions of indefinite equation)
- PHP MySQL reads data
- A. Odd Selection【BruteForce】
- win32:堆破壞的dump文件分析
- Life perception 1
- MySQL has been stopped in the configuration interface during installation
- SSL / bio pour OpenSSL Get FD
- [combinatorics] generating function (linear property | product property)
- Inheritance of ES6 class
猜你喜欢
Micro service component sentinel console call
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
Sensor debugging process
面试官:值为 nil 为什么不等于 nil ?
Talk about the design and implementation logic of payment process
Draw some simple graphics with MFC
Prototype inheritance..
MySQL grouping query
Computer graduation project PHP library book borrowing management system
Computer graduation design PHP campus address book telephone number inquiry system
随机推荐
(9) Opencv Canny edge detection
Introduction to PHP MySQL
[combinatorics] generating function (commutative property | derivative property | integral property)
TCP congestion control details | 3 design space
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
[combinatorics] generating function (shift property)
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
What kind of experience is it when the Institute earns 20000 yuan a month?
Change the single node of Postgres database into master-slave
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
win32:堆破坏的dump文件分析
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
AcWing 271. 杨老师的照相排列【多维DP】
[combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
win32:堆破壞的dump文件分析
Computer graduation design PHP makeup sales Beauty shopping mall
Grammaire anglaise Nom - Classification
PHP MySQL where clause
[combinatorics] generating function (use generating function to solve the combination number of multiple sets R)
How to install PHP on Ubuntu 20.04