#include <iostream>
#include <algorithm>
#include <math.h>
int Sign(double N){
return N >= 0 ? 1 : -1;
}
double MakeHoge(double A,double B){
int F = Sign(A);
double AA = std::abs(A);
double M = fmod(AA, B);
double N = (AA - M) / B;
if (B / 2 <= M)N++;
return F*N*B;
}
int main(){
double A = 0;
double B = 0;
A = 123, B = 12;
std::cout <<"A="<<A<<','<<"B="<<B<<" -> "<< MakeHoge(A, B) << std::endl;
A = 126, B = 12;
std::cout <<"A="<<A<<','<<"B="<<B<<" -> "<< MakeHoge(A, B) << std::endl;
A = -123, B = 12;
std::cout <<"A="<<A<<','<<"B="<<B<<" -> "<< MakeHoge(A, B) << std::endl;
A = -126, B = 12;
std::cout <<"A="<<A<<','<<"B="<<B<<" -> "<< MakeHoge(A, B) << std::endl;
A = 1.234, B = 0.01;
std::cout <<"A="<<A<<','<<"B="<<B<<" -> "<< MakeHoge(A, B) << std::endl;
A = 1.235, B = 0.01;
std::cout <<"A="<<A<<','<<"B="<<B<<" -> "<< MakeHoge(A, B) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWF0aC5oPgoKaW50IFNpZ24oZG91YmxlIE4pewoJcmV0dXJuIE4gPj0gMCA/IDEgOiAtMTsKfQoKZG91YmxlIE1ha2VIb2dlKGRvdWJsZSBBLGRvdWJsZSBCKXsKCWludCBGID0gU2lnbihBKTsKCWRvdWJsZSBBQSA9IHN0ZDo6YWJzKEEpOwoKCWRvdWJsZSBNID0gZm1vZChBQSwgQik7Cglkb3VibGUgTiA9IChBQSAtIE0pIC8gQjsKCglpZiAoQiAvIDIgPD0gTSlOKys7CgoJcmV0dXJuIEYqTipCOwoKCn0KCgppbnQgbWFpbigpewoJZG91YmxlIEEgPSAwOwoJZG91YmxlIEIgPSAwOwoKCUEgPSAxMjMsIEIgPSAxMjsKCXN0ZDo6Y291dCA8PCJBPSI8PEE8PCcsJzw8IkI9Ijw8Qjw8I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