题意:

求(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. Pandas常用方法手册

    关键缩写和包导入 在这个速查手册中,我们使用如下缩写: df:任意的Pandas DataFrame对象 同时我们需要做如下的引入: import pandas as pd 导入数据 pd.read_ ...

  2. MST + 树形 dp

    Genghis Khan(成吉思汗)(1162-1227), also known by his birth name Temujin(铁木真) and temple name Taizu(元太祖), ...

  3. Flutter全面屏适配

    笔者在这篇文章ReactNative全面屏(Android)适配问题提及了现在的全面屏问题,不仅是Android平台,IOS平台也是,给我的感觉就是手机越来越长了. 现在的手机长宽比早就不是之前的16 ...

  4. request session

    例子 url = 'http://beanhome.com/user/login' header = { "Content-Type": 'application/json', & ...

  5. mysql本地连接远程连接不上

    首先测试linux下的端口有没有开通 /etc/init.d/iptables status 查看3306端口没有开通 使用以下命令开通 /sbin/iptables -I INPUT -p tcp ...

  6. 「 深入浅出 」集合Set

    系列文章 「 深入浅出 」集合List 「 深入浅出 」java集合Collection和Map Set继承自Collection接口,不能包含有重复元素.本篇文章主要讲Set中三个比较重要的实现类: ...

  7. 关于 C#和.net 的 发展

    591. C# 1 的 委托 语法 看起来 似乎 并不 太坏 [2016-04-27 09:00:56]592. C# 2 支持 从 方法 组 到 一个 兼容 委托 类型 的 隐式 转换. [2016 ...

  8. GP工作室—系统设计

    团队作业第二次作业--系统设计 问题 答案 这个作业属于哪个课程 软件工程 这个作业要求在哪里 作业要求 团队名称 GP工作室 这个作业的目标 对项目软件进行更为详细的系统性设计 按照本游戏的设计要求 ...

  9. Redis(七):set/sadd/sismember/sinter/sdiffstore 命令源码解析

    上两篇我们讲了hash和list数据类型相关的主要实现方法,同时加上前面对框架服务和string相关的功能介绍,已揭开了大部分redis的实用面纱. 现在还剩下两种数据类型: set, zset. 本 ...

  10. if continue的用法(跳过本次循环,执行下一个循环)

    Python continue 语句跳出本次循环 当需要跳过本次循环的时候,使用continue能跳过本次循环,直接下一个循环 如下脚本: for url in alllink: if url == ...