当前位置:网站首页>Codeforces D. Buying Shovels
Codeforces D. Buying Shovels
2022-07-27 00:09:00 【Muxi Krystal】
https://codeforces.ml/contest/1360/problem/D
( Title link above )
The question :
To sum up, it is in 1~k Found within the range of n The maximum factor of x,ans=n/x
Start thinking :
from min(k,n) Start traversing down to sqrt(n) Find the maximum factor .
But the data range 1e9, The first sample will time out .
Positive solution :
from 1 Start to sqrt(n) Traverse all the factors x, And judge whether it is k Within the scope of , If in k Within the scope of ans=min(ans,n/(x)).
Complexity O(n^(1/2)), No timeout .
Some make complaints about :
I'm sorry for 1 To sqrt(n) and sqrt(n) To n The cognition of the gap is not enough .
AC Code :
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
int t,n,k;
cin>>t;
while(t--){
cin>>n>>k;
int ans=n;
for(int i=1;i<=sqrt(n);i++){
if(n%i==0){
if(n/i<=k){
ans=min(ans,n/(n/i));
}
if(i<=k){
ans=min(ans,n/i);
}
}
}
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- Mysql database complex operations: Database Constraints, query / connect table operations
- New features of ES6
- Familiarize you with the "phone book" of cloud network: DNS
- [Gorm] model relationship -hasone
- Share a regular expression
- 第2章 开发用户流量拦截器
- Method of realizing program startup and self startup through registry
- uni-app学习(二)
- 09_ Keyboard events
- 08 design of intelligent agricultural environmental monitoring system based on ZigBee
猜你喜欢

MVC three-tier architecture

How to transfer the GPX data collected by CTI RTK out of KML and SHP with attributes for subsequent management and analysis

uni-app学习(二)

Qunar travel massive indicator data collection and storage
![[2016] [paper notes] differential frequency tunable THz technology——](/img/7e/71126950250997fc436a4ee730aee7.png)
[2016] [paper notes] differential frequency tunable THz technology——

In simple terms, cchart daily lesson - happy high school lesson 57 new starting point, the old tree and new bud of colorful interface library

大疆智图、CC生产了多份数据,如何合并为一份在图新地球进行加载

The attorney general and the director of the national security service of Ukraine were dismissed
![[Gorm] model relationship -hasone](/img/90/3069059ddd09dc538c10f76d659b08.png)
[Gorm] model relationship -hasone

Upload files to OSS file server
随机推荐
简单的SQL优化
[interview: concurrency 26: multithreading: two-phase termination mode] volatile version
Design of electronic scale based on 51 single chip microcomputer
Hcip day 2_ HCIA review comprehensive experiment
94. Middle order traversal of binary tree
上千Tile的倾斜模型浏览提速,告别一块一块往外蹦的尴尬
Opencv camera calibration and distortion correction
New features of ES6
The basic operation of data tables in MySQL is very difficult. This experiment will take you through it from the beginning
银河证券网上开户佣金,网上客户经理开户安全吗
Relationship between Unicode and UTF-8
文件上传到OSS文件服务器
Typesript generic constraint
Upload files to the server
Everything you should know about wearable NFT!
Push to origin/master was rejected error resolution
Topological sorting (learning notes) introduction + judge whether there is a ring
Part II - C language improvement_ 9. Linked list
Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
The place where the dream begins ---- first knowing C language (2)