题意:

求(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. Ant Design中根据用户交互展示不同的标签

    Ant Design中根据用户交互展示不同的标签 Ant Design使用的是React框架,那么我们先看代码: <Fragment> <a onClick={() => th ...

  2. linux搭建简单的web服务器

    主要想法是:使用虚拟机的Ubuntu系统搭建http服务器,然后在window的浏览器上测试 1.先测试windows和虚拟机上的ubuntu能否相互ping通 2.下载http.tar.gz并拷贝到 ...

  3. html 鼠标指针讲解

    html 鼠标指针 详情可以看https://www.w3school.com.cn/tiy/t.asp?f=csse_cursor 测试代码: <html> <body> & ...

  4. 解决RabbitMQ远程不能访问的问题

    刚刚安装的RabbitMQ-Server-3.3.5,并且也已经开启了Web管理功能,但是现在存在一个问题: 出于安全的考虑,guest这个默认的用户只能通过http://localhost:1567 ...

  5. 关于在读取excel的文件时候,放在服务器上就报路径错误

    就是指定这个路径:C:\Program Files (x86)\IIS Express 因为在上传到服务器的时候,服务器读取的是在服务器上的路径,所以正确的思路应该是 把上传的Excel存在服务器上, ...

  6. VMware Workstation CentOS7 Linux 学习之路(1)--系统安装

      前言 很早就想学习Linux了,出去面试很多家公司都问会不会Linux,都很尴尬,一直没学过Linux,在网上也看过很多资料,也安装了VM,自己摸索着学习Linux,之前看网上的一些命令一顿操作, ...

  7. html包含html文件的方法

    我们在写asp页面的时候,常常使用include命令来包含公共文件.由于这个方法用起来非常方便,于是很多人在HTML页面里尝试使用include,但是发现根本就不起作用.这是因为,include是VB ...

  8. 洛谷 P5424 [USACO19OPEN]Snakes

    题目链接 题目描述 传说,数千年前圣帕特里克消灭了哞尔兰所有的蛇.然而,蛇们现在卷土重来了!圣帕特里克节是在每年的3月17日,所以Bessie要用彻底清除哞尔兰所有的蛇来纪念圣帕特里克. Bessie ...

  9. flask路由要点

    1.参数类型intfloatstringpath uuid<any(a, b): an> 枚举, an必须是any中的值2.多个url指向一个视图函数是可行的3.url_for('蓝图名字 ...

  10. Django2 外键遇到的坑

    # 出版社 class Publisher(models.Model): # 自增.主键 id id = models.AutoField(primary_key=True) # varchar(32 ...