防止你会写A+B problem

· · 休闲·娱乐

输入一行两个正整数 A,B,保证 1 \le A,B \le 10^9。
输出一行一个正整数 A+B。

稍微推导一下:

A+B&=(A-(A\ \mathrm{mod}\ B))+(A\ \mathrm{mod}\ B)+B\\ &=\left\lfloor\frac{A}{B}\right\rfloor \times B+(A\ \mathrm{mod}\ B)+B\\ &=\left(\left\lfloor\frac{A}{B}\right\rfloor+1\right) \times B+(A\ \mathrm{mod}\ B) \end{aligned}

于是我们就可以写出会报错的代码:

//A+B problem
//A+B=(floor(A/B)+1)*B+A mod B
#include<bits/stdc++.h>
using namespace std;
int *a=new int,*b=new int;
int main(){
    cin>>*a>>*b;
    cout<<(*a/*b+1)*(*b)+(*a)%(*b);
    return 0;
}