AOJ 0054 - Sum of Nth decimal places
doubleで10倍すれば行けると思ったら行けなかったorz.
#include <iostream> #include <cstdio> int main(){ int a, b, n; while(~scanf("%d%d%d", &a, &b, &n)){ a %= b;//小数部のみにする int res = 0; for(;n;n--){ a *= 10;//現在の少数第1位のみ取り出す res += a / b; a %= b;//整数部をなくし,計算の重複をなくす } printf("%d\n", res); } return 0; }