"HDOJ6217" BBP Formula (mathematical formula)

Source: Internet
Author: User

Test instructions: Given a fraction of an infinity, its sum is equal to π, and the hexadecimal representation of Pi is the number of the nth bit after the decimal point.

1≤n≤100000

Idea: From 78327614

C++double, it's annoying to write details.

1#include <cstdio>2#include <cstring>3#include <string>4#include <cmath>5#include <iostream>6#include <algorithm>7#include <map>8#include <Set>9#include <queue>Ten#include <vector> One using namespacestd; AtypedefLong Longll; -typedef unsignedint UINT; -typedef unsignedLong Longull; thetypedef pair<int,int>PII; -typedef vector<int>VI; - #defineFi first - #defineSe Second + #defineMP Make_pair - #defineN 11000 + #defineM 41 A #defineEPS 1e-8 at #definePi ACOs (-1) -  -  -  - intRead () - {  in    intv=0, f=1; -    CharC=GetChar (); to     while(c< -|| $&LT;C) {if(c=='-') f=-1; C=GetChar ();} +     while( -<=c&&c<= $) v= (v<<3) +v+v+c- -, c=GetChar (); -    returnv*F; the } *  $ ll Pow (ll a,ll b,ll MOD)Panax Notoginseng { -ll ans=1; the      while(b) +     { A         if(b&1) ans=ans*a%MOD; thea=a*a%MOD; +b>>=1; -     } $     returnans; $ } -  - DoubleBBP (intn,ll k,ll B) the { -     Doubleans=0;Wuyi      for(intI=0; i<=n;i++) ans+= (Pow ( -, N-i,8*I+B) *1.0/(8*i+b)); the      for(inti=n+1; i<=n+1001; i++) ans+= (POWF ( -, n-i)/(8*i+b)); -     returnk*ans; Wu } -  About intMain () $ { -     //freopen ("hdoj6217.in", "R", stdin); -     //freopen ("Hdoj6217.out", "w", stdout); -     intCAs; Ascanf"%d",&CAs); +      for(intv=1; v<=cas;v++) the     { -         intN; $scanf"%d",&n); then--; the         Doubleans=0.0; theANS=BBP (N,4,1) +BBP (n,-2,4) +BBP (n,-1,5) +BBP (n,-1,6); theans-=int(ans); -         if(ans<0) ans++; inans*= -; the         Charch; the         intp=int(ans); About         if(0<=p&&p<=9) ch=p+'0'; the          Else if(p==Ten) ch='A'; the          Else if(p== One) ch='B'; the          Else if(p== A) ch='C'; +          Else if(p== -) ch='D'; -          Else if(p== -) ch='E'; the          Else if(p== the) ch='F';Bayiprintf"Case #%d:%d%c\n", v,n+1, ch); the          the     } -     return 0; - } the      

"HDOJ6217" BBP Formula (mathematical formula)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.