当前位置:网站首页>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 .
边栏推荐
- Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
- SSL / bio pour OpenSSL Get FD
- [combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
- Talk about the design and implementation logic of payment process
- BFS - topology sort
- Micro service component sentinel console call
- 聊聊支付流程的设计与实现逻辑
- List的stream中Long对象与long判等问题记录
- English grammar_ Adjective / adverb Level 3 - multiple expression
- Embedded-c language-7
猜你喜欢

(8) HS corner detection

Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028

面试官:值为 nil 为什么不等于 nil ?

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

Class exercises

Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding
![Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]](/img/da/0a282b4773fe3909d1e5e9d19f8549.jpg)
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]

How to install PHP on Ubuntu 20.04

Talk about the design and implementation logic of payment process

The vscode code is automatically modified to a compliance code when it is formatted and saved
随机推荐
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
Embedded-c language-7
Redis core technology and practice - learning notes (11): why not just string
Module 9 operation
Self executing function
[combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
[combinatorics] generating function (summation property)
统计图像中各像素值的数量
[linux]centos 7 reports an error when installing MySQL "no package MySQL server available" no package ZABBIX server MySQL available
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
Micro service component sentinel console call
面试官:值为 nil 为什么不等于 nil ?
Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up
A. Berland Poker & 1000 [simple mathematical thinking]
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
OpenSSL的SSL/BIO_get_fd
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
Redis core technology and practice - learning notes (IX): slicing cluster
[combinatorics] generating function (example of using generating function to solve the number of solutions of indefinite equation)
An academic paper sharing and approval system based on PHP for computer graduation design