• 题意:商店里有\(k\)个包裹,第\(i\)个包裹中含有\(i\)个物品,现在想要买\(n\)物品,你可以选择某一个包裹购买任意次,使得物品数刚好等于\(n\),求最少的购买次数.

  • 题解:首先,假如\(k\ge n\),那么只用买一次.否则,我们枚举\(1\)~\(\sqrt n\),若\(n\ mod\ i=0\):

    ​ 1.\(n/i\le k\),那么\(i\)一定是我们所需要的最小购买次数,

    ​ 2.\(n/i>k\),只要\(i\le k\),我们就维护\(ans\)和\(n/i\)的最小值.

    ​ 纸上谈来终觉浅,要自己去好好思考,对数字敏感一点,也就想出来了.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL; int t;
    ll n,k; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>t;
    while(t--){
    cin>>n>>k;
    if(n<=k){
    printf("1\n");
    }
    else{
    bool ok=0;
    ll ans=INF;
    for(ll i=1;i*i<=n;++i){
    if(n%i==0){
    if(n/i<=k){
    ok=1;
    ans=i;
    break;
    }
    else{
    if(i<=k){
    ans=min(ans,n/i);
    }
    }
    }
    }
    printf("%lld\n",ans);
    } } return 0;
    }

Codeforces Round #644 (Div. 3) D. Buying Shovels (数学)的更多相关文章

  1. Codeforces Round #644 (Div. 3)

    比赛链接:https://codeforces.com/contest/1360 A - Minimal Square 题意 计算能包含两个 $a \times b$ 矩形的最小正方形的面积. 题解 ...

  2. [每日一题2020.06.11]Codeforces Round #644 (Div. 3) H

    A-E见 : 这里 题目 我觉得很有必要把H拿出来单独发( 其实是今天懒得写题了 ) problem H 一个从 1 到 $ 2^m - 1$ 的长度为m的连续二进制序列, 删去指定的n个数, 问剩余 ...

  3. [每日一题2020.06.10]Codeforces Round #644 (Div. 3) ABCDEFG

    花了5个多少小时总算把div3打通一次( 题目链接 problem A 题意 : 两个x*y的矩形不能重叠摆放, 要放进一个正方形正方形边长最小为多少 先求n = min(2x, 2y, x+y) 再 ...

  4. Codeforces Round #180 (Div. 2) C. Parity Game 数学

    C. Parity Game 题目连接: http://www.codeforces.com/contest/298/problem/C Description You are fishing wit ...

  5. Codeforces Round #188 (Div. 2) C. Perfect Pair 数学

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  6. Codeforces Round #274 (Div. 1) B. Long Jumps 数学

    B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...

  7. Codeforces Round #200 (Div. 1)A. Rational Resistance 数学

    A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  8. Codeforces Round #369 (Div. 2) D. Directed Roads 数学

    D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and ...

  9. Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

    C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...

随机推荐

  1. 【Azure Developer】Python代码通过AAD认证访问微软Azure密钥保管库(Azure Key Vault)中机密信息(Secret)

    关键字说明 什么是 Azure Active Directory?Azure Active Directory(Azure AD, AAD) 是 Microsoft 的基于云的标识和访问管理服务,可帮 ...

  2. MySQL select if 查询最后一个主键 id

    查询最后一个主键id SELECT IF(MAX(id) IS NULL, 0, MAX(id)) AS maxid FROM users; 查询最小的主键id SELECT IF(MIN(id) I ...

  3. 【Spring】Spring中的Bean - 4、Bean的生命周期

    Bean的生命周期 简单记录-Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)-Spring中的Bean 了解Spring中Bean的生命周期有何意义? 了解Sp ...

  4. LeetCode700. 二叉搜索树中的搜索

    题目 简单递归 1 class Solution { 2 public: 3 TreeNode* searchBST(TreeNode* root, int val) { 4 if(!root) re ...

  5. 视图V_160M和表T_160M的维护

    今天发现一个视图,通过SM30居然无法维护,这个视图就是V_160M,表为T_160M,是采购相关的系统消息, 不过别着急,有办法维护的,呵呵,看下面: 试一试OMCQ这个事物代码吧! 分享出来,给需 ...

  6. MyBatis初级实战之六:一对多关联查询

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  7. django url别名和反向解析 命名空间

    url别名和反向解析 我们平时写的url名字都是死的,如果项目过大,需要项目中某个文件名改动一下,那么改动起来就不是一般的麻烦了,所以我们就在定义的时候给url起一个别名,以后不管哪个文件中运用都是用 ...

  8. 1、进程管理常用命令和进程ID

    常用命令 1. ps (英文全拼:process status)命令用于显示当前进程的状态,类似于 windows 的任务管理器. 详细介绍参照:https://www.runoob.com/linu ...

  9. 支付宝沙箱环境使用(Alipay Easy SDK ) .Net示例

    新版服务端 SDK(Alipay Easy SDK)适用于 Java.C#.PHP 编程语言,对开放能力的 API 进行了更加贴近高频场景的精心设计与裁剪,简化了服务端调用方式,让开发者享受极简编程体 ...

  10. jQuery 点击当前展开其他隐藏

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...