HDU 2940 Hex factorial (simple high precision)

Source: Internet
Author: User
Tags cmath

Test instructions: Ask for a n! The number of 16 binary representations of 0.

High-precision simulations, or direct java. Here you can give a high-precision template.

#include <cstdio> #include <cstdio> #include <cmath> #include <queue> #include <stack># include<string> #include <cstring> #include <iostream> #include <map> #include <vector># include<algorithm> #include <set> #include <cmath>using namespace std;const int mmax = 10010;const int    INF = 0x3fffffff;struct bignum{int Sz;    int Num[mmax];        void print () {for (int i=sz-1;i>=0;i--) printf ("%0x", Num[i]);    Puts ("");        } bignum () {} bignum (int Sz,char *a) {sz=sz;        for (int i=0;i<sz;i++) {num[i]=a[sz-1-i]-' 0 ';        }} bignum (int sz,int *a) {sz=sz;    for (int i=0;i<sz;i++) num[i]=a[i];        } bignum (int x) {sz=0;            while (x) {num[sz++]=x%16;        x/=16;        }} Bignum operator + (const bignum &a) {int Tmp[mmax];        memset (tmp,0,sizeof tmp); int Len=max(SZ,A.SZ);            for (int i=0;i<len;i++) {tmp[i]+=num[i]+a.num[i];            TMP[I+1]+=TMP[I]/10;        tmp[i]%=10;    } return Bignum (len+ (tmp[len]?1:0), TMP);        } bignum Operator-(const bignum &a) {int Tmp[mmax];        memset (tmp,0,sizeof tmp);        int Len=max (SZ,A.SZ);            for (int i=0;i<len;i++) {tmp[i]+=num[i]-a.num[i];                if (tmp[i]<0) {tmp[i+1]-=1;            tmp[i]+=10;        }} for (int i=len-1;i>=0;i--) {if (Tmp[i]) return Bignum (I+1,TMP);    } return Bignum (1,TMP);        } bignum operator * (const bignum &a) {int Tmp[mmax];        memset (tmp,0,sizeof tmp);            for (int i=0;i<sz;i++) for (int j=0;j<a.sz;j++) {tmp[i+j]+=num[i]*a.num[j];  } for (int i=0;i<sz+a.sz;i++) {tmp[i+1]+=tmp[i]/16;          tmp[i]%=16;        } for (int i=sz+a.sz-1;i>=0;i--) {if (Tmp[i]) return Bignum (I+1,TMP);    } return Bignum (1,TMP);    }};int Main () {int n;        while (Cin>>n && n>=0) {bignum ans (1);        for (int i=1;i<=n;i++) ans=ans*bignum (i);        int cnt=0; for (int I=0;i<ans.        sz;i++) {if (ans.num[i]==0) cnt++;    } printf ("%d\n", CNT); } return 0;}

HDU 2940 Hex factorial (simple high precision)

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.