Codeforces 1087B Div Times Mod(数学+暴力)
题意:
求(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(数学+暴力)的更多相关文章
- 【Codeforces】B. Div Times Mod
B. Div Times Mod time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- codeforces #592(Div.2)
codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...
- Codeforces #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- delphi “div”、“mod”、“\”除法运算符的区别与使用方法(附带FORMAT使用方法)
Delphi中和除法相关的算术运算符有: div.mod和符号“\” 下面分别对他们的作用.操作数类型和返回值类型进行一下介绍: div:对2个整数进行除,取商,操作数需是integer类型,返回值也 ...
- codeforces #578(Div.2)
codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...
- codeforces #577(Div.2)
codeforces #577(Div.2) A Important Exam A class of students wrote a multiple-choice test. There are ...
随机推荐
- model流程
@RequestMapping("toDetail.do") public ModelAndView toDetail(HttpServletRequest request,Htt ...
- schedule of 2016-09-26~2016-10-02(Monday~Sunday)——1st semester of 2nd Grade
2016/9/26 Monday 1.make ppt for this afternoon's group meeting 2.ask teacher Xiqi&Liu some probl ...
- Cannot access org.springframework.context.ConfigurableApplicationContext
Cannot access org.springframework.context.ConfigurableApplicationContext 需要将有问题的模块 删除 后重新导入 即可 IDEA ...
- 【记】本地远程连接VM VirtualBox中虚拟机Centos6的数据库MySQL
目标:远程连接虚拟机中的MySQL 效果图如下 1. VBox设置好端口转发 具体步骤请看 VM VirtualBox 网络地址转换(NAT)使用详解 2. MySQL授权 如果这时我们就去远程连接M ...
- 解决:'chromedriver' executable needs to be in PATH的问题
0.前言 今天写一个B站登录的模拟器时,用到了Chrome浏览器,但是会报了一个异常"'chromedriver' executable needs to be in PATH", ...
- 小白学Java:迭代器原来是这么回事
目录 小白学Java:迭代器原来是这么回事 迭代器概述 迭代器设计模式 Iterator定义的方法 迭代器:统一方式 Iterator的总结 小白学Java:迭代器原来是这么回事 前文传送门:Enum ...
- 区间dp - 全部按下一列石头
There is one last gate between the hero and the dragon. But opening the gate isn't an easy task. The ...
- JS 点击验证码刷新
<img src="/get_valid_img" id="valid-img" title="点击再换一张" class=" ...
- IDEA中springboot的热部署
在pom.xml文件中添加依赖 <!--添加热部署--> <dependency> <groupId>org.springframework.boot</gr ...
- js多图预览及上传功能
<%-- Created by IntelliJ IDEA. User: Old Zhang Date: 2018/12/27 Time: 11:17 To change this templa ...