当前位置:网站首页>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 .
边栏推荐
- Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up
- Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
- The vscode code is automatically modified to a compliance code when it is formatted and saved
- [combinatorics] generating function (property summary | important generating function)*
- Getting started with deops
- Mathematical formula (test)
- TCP congestion control details | 3 design space
- STM32 realizes 74HC595 control
- 模块九作业
- Theoretical description of linear equations and summary of methods for solving linear equations by eigen
猜你喜欢
What kind of experience is it when the Institute earns 20000 yuan a month?
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
English语法_名词 - 分类
Valentine's day, send you a little red flower~
Interviewer: why is the value nil not equal to nil?
SQL injection -day16
Redis cache avalanche, penetration, breakdown
PHP MySQL inserts data
How to install PHP on Ubuntu 20.04
聊聊支付流程的設計與實現邏輯
随机推荐
Enterprise custom form engine solution (12) -- form rule engine 2
Embedded-c language-7
Image 24 bit depth to 8 bit depth
Computer graduation design PHP makeup sales Beauty shopping mall
分布式的任务分发框架-Gearman
Postfix 技巧和故障排除命令
[combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
小程序 多tab 多swiper + 每个tab分页
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
[tutorial] build your first application on coreos
Micro service component sentinel console call
Website with JS doesn't work in IE9 until the Developer Tools is activated
Summary and Reflection on the third week of winter vacation
Three gradient descent methods and code implementation
Talk about the design and implementation logic of payment process
Computer graduation project PHP library book borrowing management system
Fedora 21 installs lamp host server
[combinatorics] generating function (generating function application scenario | using generating function to solve recursive equation)
ES6类的继承