当前位置:网站首页>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 .
边栏推荐
- Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
- Getting started with deops
- PHP MySQL reads data
- [combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
- Redis core technology and practice - learning notes (VII) sentinel mechanism
- STM32 realizes 74HC595 control
- 解决Zabbix用snmp监控网络流量不准的问题
- Image 24 bit depth to 8 bit depth
- Change the single node of Postgres database into master-slave
- How do microservices aggregate API documents? This wave of operation is too good
猜你喜欢

Redis core technology and practice - learning notes (11): why not just string

List的stream中Long对象与long判等问题记录

Codeforces Round #803 (Div. 2) C. 3SUM Closure

SQL injection -day16
![Golang string (string) and byte array ([]byte) are converted to each other](/img/41/20f445ef9de4adf2a2aa97828cb67f.jpg)
Golang string (string) and byte array ([]byte) are converted to each other

微服务组件Sentinel控制台调用

Embedded-c language-7

Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028

Three gradient descent methods and code implementation

Redis on local access server
随机推荐
Have you learned the correct expression posture of programmers on Valentine's day?
STM32 realizes 74HC595 control
The vscode code is automatically modified to a compliance code when it is formatted and saved
[linux]centos 7 reports an error when installing MySQL "no package MySQL server available" no package ZABBIX server MySQL available
Win 11 major updates, new features love love.
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Talk about the design and implementation logic of payment process
[tutorial] build your first application on coreos
分布式的任务分发框架-Gearman
English grammar_ Noun classification
[combinatorics] generating function (generating function application scenario | using generating function to solve recursive equation)
Setinterval CPU intensive- Is setInterval CPU intensive?
Use of unsafe class
How to deploy applications on kubernetes cluster
Records of long objects and long judgments in the stream of list
Prototype inheritance..
The third day of writing C language by Yabo people
Valentine's day, send you a little red flower~
The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
AcWing 271. 杨老师的照相排列【多维DP】