当前位置:网站首页>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 .
边栏推荐
- [combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- Win 11 major updates, new features love love.
- 模块九作业
- 小程序 多tab 多swiper + 每个tab分页
- Enterprise custom form engine solution (12) -- form rule engine 2
- PHP MySQL Update
- Computer graduation design PHP sports goods online sales system website
- What kind of experience is it when the Institute earns 20000 yuan a month?
- Ssl/bio of OpenSSL_ get_ fd
猜你喜欢
SQL injection -day16
The third day of writing C language by Yabo people
English grammar_ Adjective / adverb Level 3 - multiple expression
聊聊支付流程的设计与实现逻辑
PHP MySQL inserts data
PHP MySQL preprocessing statement
PHP MySQL inserts multiple pieces of data
What kind of experience is it when the Institute earns 20000 yuan a month?
Redis core technology and practice - learning notes (IX): slicing cluster
How to deploy applications on kubernetes cluster
随机推荐
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
Introduction to PHP MySQL
SSL / bio pour OpenSSL Get FD
微服务组件Sentinel控制台调用
Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding
Prototype inheritance..
An academic paper sharing and approval system based on PHP for computer graduation design
PHP MySQL inserts data
Kotlin的协程:上下文
Use of unsafe class
Gear2021 monthly update - December
Postfix tips and troubleshooting commands
PHP processing - watermark images (text, etc.)
Have you learned the correct expression posture of programmers on Valentine's day?
Records of long objects and long judgments in the stream of list
Redis core technology and practice - learning notes (VII) sentinel mechanism
PHP MySQL preprocessing statement
[combinatorics] generating function (example of generating function | calculating generating function with given general term formula | calculating general term formula with given generating function)
Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
[combinatorics] generating function (linear property | product property)