Hatena::Grouptopcoder

naoya_t@topcoder RSSフィード

2008-12-26

SRM389 Div1 Easy: ApproximateDivision

| 10:11 | SRM389 Div1 Easy: ApproximateDivision - naoya_t@topcoder を含むブックマーク はてなブックマーク - SRM389 Div1 Easy: ApproximateDivision - naoya_t@topcoder SRM389 Div1 Easy: ApproximateDivision - naoya_t@topcoder のブックマークコメント

簡単。

class ApproximateDivision {
public:
  double quotient(int a, int b, int terms) {
    int t=1;
    while(1){ if(t<b) t*=2; else break; }
    int c=t-b;
    double d=0, e=1.0/t, r=1.0*c/t;
    rep(i,terms) {d+=e; e*=r;}
    return d*a;
  }
};