zoukankan      html  css  js  c++  java
  • 一本通1653方程的解

    sol:隔板法很明显,但为了增加难度,就要用高精。。。

    Ps:难度不够,高精来凑

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0'); return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const ll Base=10000,power=4;
    struct Bignum
    {
        ll a[1005];
        Bignum()
        {
            memset(a,0,sizeof a);
        }
        Bignum(ll x)
        {
            memset(a,0,sizeof a);
            while(x)
            {
                a[++a[0]]=x%Base; x/=Base;
            }
            return;
        }
        inline void Add(int x)
        {
            if(x||a[0]) a[++a[0]]=x;
            return;
        }
        inline void Rev()
        {
            reverse(a+1,a+a[0]+1);
            return;
        }
        inline void print()
        {
            int i;
            write(a[a[0]]);
            for(i=a[0]-1;i>=1;i--)
            {
                if(a[i]<1000) putchar('0');
                if(a[i]<100) putchar('0');
                if(a[i]<10) putchar('0');
                write(a[i]);
            }
        }
        #define P(x) x.print(),putchar(' ')
        #define Pl(x) x.print(),putchar('
    ')
    };
    inline Bignum operator*(const Bignum &p,ll q)
    {
        int i;
        Bignum ans=p;
        for(i=1;i<=ans.a[0];i++) ans.a[i]*=q;
        for(i=1;i<=ans.a[0];i++)
        {
            ans.a[i+1]+=ans.a[i]/Base;
            ans.a[i]%=Base;
        }
        while(ans.a[ans.a[0]+1])
        {
            ans.a[0]++;
            ans.a[ans.a[0]+1]+=ans.a[ans.a[0]]/Base;
            ans.a[ans.a[0]]%=Base;
        }
        return ans;
    }
    inline bool operator<(const Bignum &p,const Bignum &q)
    {
        if(p.a[0]!=q.a[0]) return p.a[0]<q.a[0];
        int i;
        for(i=p.a[0];i>=1;i--) if(p.a[i]!=q.a[i])
        {
            return p.a[i]<q.a[i];
        }
        return false;
    }
    inline bool operator>=(const Bignum &p,const Bignum &q)
    {
        return !(p<q);
    }
    inline Bignum operator-(const Bignum &p,const Bignum &q)
    {
        int i;
        Bignum ans=p;
        for(i=1;i<=q.a[0];i++)
        {
            ans.a[i]-=q.a[i];
            if(ans.a[i]<0) ans.a[i]+=Base,ans.a[i+1]--;
        }
        while(!ans.a[ans.a[0]]) ans.a[0]--;
        return ans;
    }
    inline Bignum operator/(const Bignum &p,ll q)
    {
        ll i,Sum=0;
        Bignum ans;
        ans.a[0]=p.a[0];
        for(i=ans.a[0];i>=1;i--)
        {
            Sum=Sum*Base+p.a[i];
            ans.a[i]=Sum/q;
            Sum%=q;
        }
        while(ans.a[0]&&(!ans.a[ans.a[0]])) ans.a[0]--;
        return ans;
    }
    inline ll Ksm(ll x,ll y,ll Mod)
    {
        ll ans=1;
        while(y)
        {
            if(y&1) ans=ans*x%Mod;
            x=x*x%Mod;
            y>>=1;
        }
        return ans;
    }
    ll C(ll n,ll m)
    {
        int i;
        Bignum ans=Bignum(1);
        for(i=n-m+1;i<=n;i++)
        {
            ans=ans*i;
        }
        for(i=2;i<=m;i++)
        {
            ans=ans/i;
        }
        Pl(ans);
    }
    int main()
    {
        ll n,m,Num;
        R(m);
        Num=read()%1000;
        n=Ksm(Num,Num,1000);
        C(n-1,m-1);
        return 0;
    }
    /*
    input
    7 3
    output
    230230
    */
    View Code
  • 相关阅读:
    Beginning UICollectionView In iOS 6: Part 2/2
    Intermediate Debugging with Xcode 4.5
    Xcode4: Running Application Tests From The Command Line in iOS
    Mac 在open with列表中清除重复应用程序
    Beginning UICollectionView In iOS 6: Part 1/2
    Xcode Apple MachO Linker warning
    Running Xcode 4 unit tests from the command line
    25 iOS App Performance Tips & Tricks
    Introduction to InApp Purchases in iOS 6 Tutorial
    iPhone Development 101: Cocoa: Notifications
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10533586.html
Copyright © 2011-2022 走看看