题意:

求(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. 日志冲突解决方案(基于gradle)

    日志冲突解决方案 前提:我使用gradle管理项目 最近在项目中需要用curator客户端操作zookeeper,在maven仓库拉取的jar包导致日志冲突,会报以下的错误: 经常会有如上图2处红色框 ...

  2. iSO垂直滑动条VerticalSlider

    由于项目需要实现一个垂直的Slider,滑动条使用UIlabel实现,按钮使用UIButton,按钮可以设置背景图片,代码如下 VerticalSlider.h // // VerticalSlide ...

  3. Linux学习_菜鸟教程_2

    Linux 系统目录 /bin:  bin是Binary的缩写,这个目录存放着最经常使用的命令. /boot:  存放启动Linux时的一些核心文件,包括一些连接文件以及镜像文件. /dev : de ...

  4. 【转载】解决KindEditor图片上传对话框位置异常问题(浏览器放大缩小时对话框不见了)

    今早在整理文件上传模块的时候,发现富文本编辑器 kindeditor 上传图片的对话框无法显示,其实对话框已经生成了,但是它没有top值,所以在页面上看不见. 捣鼓了一个多小时,代码看了一大串,没解决 ...

  5. 【Javaweb学习笔记】XML和约束模式

    一.XML语法 xml 可扩展标记语言,w3c组织发布的,用于保存有关系的数据,作为配置文件,描述程序模块之间的关系 xml 文件开头必须包括下面的标签: <?xml version=" ...

  6. 简单 hash 入门题目

    题目描述 NOIP 复赛之前,HSD 桑进行了一项研究,发现人某条染色体上的一段 DNA 序列中连续的 kkk 个碱基组成的碱基序列与做题的 AC 率有关!于是他想研究一下这种关系.现在给出一段 DN ...

  7. Nginx代理服务——正向代理

    正向代理 在/opt/app/code的目录下创建一个joy.html文件 <html> <head> <meta charset="utf-8"&g ...

  8. java byte/short/char补充(了解)

    1.在数学运算中会自动提升数据类型为 int 2.在基本赋值中,若右册的常量不超过取值范围,javac 添加 强制转换,否则报错 3.若右册 含有 变量 而不是直接使用常量相加,编译报错 例子 pub ...

  9. SSM框架整合中,不报错,数据库只能存ID进去问题解决

    嗯,这个错误其实不能算错误,是粗心造成的,在配置文件中对于传递的参数没有写#字符,直接写的的属性名.居然错了两次,哎!!! 嗯,还有一个问题,在动态SQL中,if标签中test属性中判断时,不能用大写 ...

  10. 20200104模拟赛 问题A 图样

    题目 分析: 老规矩,遇到期望要准备好随时投降... 大致想到了按位处理,然后分别下去搜索,再用组合数加加减减一下... 但是两个连通块之间连边的期望怎么算呢? 很好,投降... 下来看题解... 果 ...