题意:

求(x div k) * (x mod k) = n的最小解x,保证有解

1<=n<=1e6, k<=1000,1s

思路:

注意到k的范围是1e3,

1<=x mod k<1e3,这并不能看到x的上限

而x div k要达到1e6,所以x最大可能达到1e9

所以不能枚举x

因为两个因子相乘正好为n,所以我们可以枚举x mod k

x mod k<=n且x mod k < k

所以我们只需枚举[1,k)就可以了

此时x mod k = i ,且n%i==0

所以x div k = n / i

所以x = n / i * k + i;

算出最小值即可

代码:

枚举范围错了居然也能pp。。还好没掉分

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int main(){
ll n, k;
scanf("%lld %lld",&n, &k); //(x/k)*(x%k)==n
ll ans = 0x3f3f3f3f3f3f3f3f;
for(ll i = ; i < k; i++){
if(n%i==){
//x/k=n/i
//x%k=i
ll y= n/i;
ans = min(y*k+i,ans);
}
}
printf("%lld", ans);
return ;
} /* */

Codeforces 1087B Div Times Mod(数学+暴力)的更多相关文章

  1. 【Codeforces】B. Div Times Mod

    B. Div Times Mod time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  3. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  4. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

  5. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  6. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  7. delphi “div”、“mod”、“\”除法运算符的区别与使用方法(附带FORMAT使用方法)

    Delphi中和除法相关的算术运算符有: div.mod和符号“\” 下面分别对他们的作用.操作数类型和返回值类型进行一下介绍: div:对2个整数进行除,取商,操作数需是integer类型,返回值也 ...

  8. codeforces #578(Div.2)

    codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...

  9. codeforces #577(Div.2)

    codeforces #577(Div.2) A  Important Exam A class of students wrote a multiple-choice test. There are ...

随机推荐

  1. redux一些自习时候自己写的的单词

    setState:设置状态 render:渲染,挂载 dispatchEvent : 派发事件 dispatch:分发,派遣:库里的一个方法,简而言之相当于一个actions和reducer监听方法更 ...

  2. IDEA 配置及常用快捷键

    常用快捷键 1.Ctrl+Alt+T 把选择的代码放入 try{} 或者 if{} 里 2.Ctrl+O 重写方法提示 3.Alt+回车 导包提示 4.Alt+/ 代码提示(默认不是这个,需要参照后文 ...

  3. ubuntu16.04 docker kubernetes(k8s) istio 安装

    版本: docker: 19.03.5 kubernetes: 1.17.0 istio: 1.4.3 步骤一:给ubuntu换源 https://www.cnblogs.com/lfri/p/106 ...

  4. Java中的SPI扩展机制(有demo)

    参考连接:https://www.jianshu.com/p/3a3edbcd8f24 一.什么是SPI SPI ,全称为 Service Provider Interface,是一种服务发现机制.它 ...

  5. Webpack实战(四):教教你如何轻松搞定-预处理器(loader)

    前面三节,我主要给大家分享了有关webpack的一些配置的知识点,如何打包js文件,而如果我们遇到其他类型的资源如图片.css.字体font等等,我们该如何处理呢?今天会介绍预处理器(loader), ...

  6. 19南京网络赛A 扫描线

    题目链接:https://nanti.jisuanke.com/t/41298 扫描线的简单题,题目难在找宫殿的价值(°ー°"),比赛时将近100多行代码找价值,纯模拟,看到题解哭了. 存下 ...

  7. 史上最简约的vi教程,复制和粘贴

    上一篇博客,讲了"新手"如何"入门"vi,解决了"两眼一抹黑"的情况.知道在vi下如何进行基本的操作,如部署在Linux下的项目,修改配置文 ...

  8. 域渗透之票据传递攻击(pass the ticket,ptt)

    票据传递攻击(PtT)是一种使用Kerberos票据代替明文密码或NTLM哈希的方法.PtT最常见的用途可能是使用黄金票据和白银票据,通过PtT访问主机相当简单. 1.ptt攻击的部分 就不是简单的N ...

  9. 聊一聊 InnoDB 引擎中的这些索引策略

    在上一篇中,我们简单的介绍了一下 InnoDB 引擎的索引类型,这一篇我们继续学习 InnoDB 的索引,聊一聊索引策略,更好的利用好索引,提升数据库的性能,主要聊一聊覆盖索引.最左前缀原则.索引下推 ...

  10. 玩转Django2.0---Django笔记建站基础九(一)(Auth认证系统)

    第九章 Auth认证系统 Django除了有强大的Admin管理系统之外,还提供了完善的用户管理系统.整个用户管理系统可分为三大部分:用户信息.用户权限和用户组,在数据库中分别对应数据表auth_us ...