Loading

Educational Codeforces Round 13 A. Johny Likes Numbers

题目传送

题目分析

题意:给两个数字\(n\)\(k\),让你在\(k\)的倍数中,找出大于\(n\)的最小数字\(x\),即\(n>x\)

这道题很裸也很简单,答案就是\(k\times (\lfloor \frac{n}{k} \rfloor +1)\)这个动动脑子就能想明白

这里鄙人自己个给出了一个不太严谨的数学证明:

\[\text{设存在两个正整数A、B,其中}A>B \\ \text{设存在正整数}n,使得A<n\times B恒成立,即n>\frac{A}{B} \\ 已知\exists \sigma \in [0,1),\lfloor \frac{A}{B}\rfloor +\sigma=\frac{A}{B}\\ 则\lfloor \frac{A}{B}\rfloor+1>\lfloor \frac{A}{B}\rfloor +\sigma=\frac{A}{B} \\ 故存在n=\lfloor \frac{A}{B}\rfloor+1使得n>\frac{A}{B}恒成立 \]

这里在留下一个简单的问题:如果这道题让你求\(n\ge x\)呢?

AC代码

#include <bits/stdc++.h>
#define io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rT printf("\nTime used = %.3lf\n", (double)clock()/CLOCKS_PER_SEC)

using namespace std;
typedef long long ll;
ll n, k;

int main() {
    io;
    cin >> n >> k;
    cout << k * (n / k + 1) << '\n';
    
    return 0;
}

上述问题答案:\(k\times \lceil \frac{n}{k} \rceil\),代码实现略

posted @ 2021-04-01 23:33  Frank_Ou  阅读(44)  评论(0编辑  收藏  举报