1 条题解

  • 0
    @ 2021-6-15 14:11:05

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    long long w=1e9;
    long long c[20001],s1[20001],s2[20001],len1,len2;
    void chen1(int k)
    {int i;
        memset(c,0,sizeof(c));
         for (i=1;i<=len1;i++)
         {
          c[i]+=s1[i]*k;
          if (c[i]>=w)
            {
                c[i+1]+=c[i]/w;
                c[i]%=w;
            }
         }
         if (c[len1+1]) len1++;
         while (c[len1]>=w)
         {
            c[len1+1]+=c[len1]/w;
            c[len1]%=w;
            len1++;    
         }
         for (i=1;i<=len1;i++)
         {
            s1[i]=c[i];
         }
    }
    void chen2(int k)
    {int i;
        memset(c,0,sizeof(c));
         for (i=1;i<=len2;i++)
         {
          c[i]+=s2[i]*k;
          if (c[i]>=w)
            {
                c[i+1]+=c[i]/w;
                c[i]%=w;
            }
         }
         if (c[len2+1]) len2++;
         while (c[len2]>=w)
         {
            c[len2+1]+=c[len2]/w;
            c[len2]%=w;
            len2++;    
         }
         for (i=1;i<=len2;i++)
         {
            s2[i]=c[i];
         }
    }
    void epow1(int x,int y)
    {int i;
        for (i=1;i<=y;i++)
         chen1(x);
    }
    void epow2(int x,int y)
    {int i;
        for (i=1;i<=y;i++)
         chen2(x);
    }
    void print1()
    {int i,j;
        printf("%lld",s1[len1]);
        for (i=len1-1;i>=1;i--)
        {int k=0;
        long long x=s1[i];
            while (x)
            {k++;
                x/=10;
            }
           for (j=9;j>k;j--)
            printf("0");
            if (s1[i])
            printf("%lld",s1[i]);
        }
    }
    void print2()
    {int i,j;
        printf("%lld",s2[len2]);
        for (i=len2-1;i>=1;i--)
        {int k=0;
        long long x=s2[i];
            while (x)
            {k++;
                x/=10;
            }
           for (j=9;j>k;j--)
            printf("0");
            if (s2[i])
            printf("%lld",s2[i]);
        }
    }
    long long gcd(long long a,long long b)
    {
        if (b==0)
        {
            return a;
        }
         long long r=gcd(b,a%b);
          return r;
    }
    int main()
    {int T,l,i,n,k;
    //freopen("ans.out","w",stdout);
        cin>>T;
        for (l=1;l<=T;l++)
        {
            scanf("%d%d",&n,&k);
            if (n>k) 
            {
                cout<<0<<' '<<1<<endl;
                continue;
            }
            memset(s1,0,sizeof(s1));
            memset(s2,0,sizeof(s2));
            s1[1]=1;
            len1=1;
           long long x=k-n+1;
           for (i=1;i<=n;i++)
           {
                long long d=gcd(k,x);
                x/=d;
                 chen1(k/d);
           } 
            len2=1;
            s2[1]=1;
            epow2(k+1,n-1);
            chen2(x);
            print2();
            cout<<' ';
            print1();
            cout<<endl;
        }
    }
    
    • 1

    信息

    ID
    980
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者