A Commentary Boxes

算出$N \pmod M$

然后分别讨论是加还是减

 

#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#define int long long 
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, M, A, B;
main() {
    N = read(); M = read(); A = read(), B = read();
    int res = N % M;
    printf("%lld", min((M - res) * A, res * B));
}
A

相关文章:

  • 2021-07-11
  • 2022-03-02
  • 2022-01-01
  • 2021-05-17
  • 2022-02-02
  • 2021-08-26
猜你喜欢
  • 2022-12-23
  • 2021-05-25
  • 2021-12-23
  • 2021-05-17
  • 2021-09-25
相关资源
相似解决方案