高精度为什么WA,样例过了

P1591 阶乘数码

Chen_Three @ 2024-07-17 11:04:30

#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
const int N = 10000 ;
char S[N] ;
char T[N] ;
struct bigNumber{
    int len , x[N] ;
    bigNumber( ) {len = 1 ; memset(x, 0 , sizeof(x)) ;}
    void print() {
        for (int i = len ;i;i--) printf("%d",x[i]) ;puts("") ;
    }
} a,b,c;//f[N][N] , s[N][N] , a,b,c;

inline bool operator <(bigNumber a, bigNumber b) {
    if (a.len != b.len ) return a.len< b.len ;
    for (int i = a.len;i ;i--) 
        if (a.x[i] != b.x[i]) return a.x[i] <b.x[i] ;
    return 0 ;
}

inline bool operator <=(bigNumber a, bigNumber b) { 
    if (a.len != b.len ) return a.len< b.len ;
    for (int i = a.len;i ;i--) 
        if (a.x[i] < b.x[i]) return 1 ;
        else if (a.x[i] >b.x[i]) return 0 ;
    return 1 ;
}

bigNumber fix(bigNumber a ) {
    for (int i = 1;i< a.len;++ i) {
        if (a.x[i] <0) a.x[i]+= 10 , a.x[i+1] -- ;
        a.x[i+1] += a.x[i] / 10 ;
        a.x[i] %= 10 ;
    }
    while (a.x[a.len] >=10 ) {
        a.x[a.len + 1] += a.x[a.len] / 10 ;
        a.x[a.len] %= 10 ; a.len ++ ;
    }
    while (!a.x[a.len] && a.len>1) a.len-- ;
    return a ;  
}

inline bigNumber operator *(bigNumber a , int b) {
    for (int i = 1;i<= a.len ;++ i ) a.x[i] *= b ;
    return fix(a) ;
}
inline bigNumber operator *(bigNumber a , bigNumber b) {
    bigNumber c ;   
    c.len = a.len + b.len -1 ; 
    for (int i = 1;i<= a.len ;++ i) 
        for (int j = 1;j<=b.len ; ++j) 
            c.x[i+j-1] += a.x[i] * b.x[j] ;
    return fix(c) ;
}

inline bigNumber operator +(bigNumber a , int b) {
    a.x[1] += b ;
    return fix(a) ;
}

inline bigNumber operator +(bigNumber a , bigNumber b) {
    bigNumber c ;
    c.len = max(a.len, b.len ) ;
    for (int i = 1;i<= c.len ;++ i) c.x[i] = a.x[i] + b.x[i] ;
    return fix(c) ;
}

inline bigNumber operator -(bigNumber a , int b) {
    a.x[1] -= b ;
    return fix(a) ;
}

inline bigNumber operator -(bigNumber a , bigNumber b) {
    bigNumber c ;
    c.len = max(a.len, b.len ) + 1 ;
    for (int i = 1;i<= c.len ;++ i) c.x[i] = a.x[i] - b.x[i] ;
    return fix(c) ;
}

inline bigNumber operator /(bigNumber a, int y) 
{
    int x = 0 ;
    bigNumber c ;
    c.len = a.len ;
    for (int i = c.len; i>0; --i) {
        c.x[i] = (x* 10 + a.x[i]) / y ; 
        x = (x* 10+ a.x[i]) % y ; 
    }       
    return fix(c) ;
} 

inline bigNumber operator /(bigNumber a, bigNumber b) {
    bigNumber c ;   
    int s= 0 ;
    while (a.len >b.len) b= b * 10 , s++ ;
    while (s>=0) {
        c= c * 10 ; 
        while (b <= a) c=c+1 , a = a- b;
        b= b / 10  , s-- ; 
    }
    return fix(c) ; 
}

inline bigNumber operator %(bigNumber a, int y) 
{
    bigNumber c = a / y ;
    a = a - c * y ;
    return fix(a) ; 
}

inline bigNumber operator %(bigNumber a, bigNumber b) 
{
    int s= 0 ;
    while (a.len >b.len) b= b * 10 , s++ ;
    while (s>=0) {
        while (b <= a) a = a - b;   
        b= b / 10  , s-- ; 
    }
    return fix(a) ; 
}

inline bigNumber poww(int m, int p) 
{
    a.x[1] = 1 ;
    b.x[1] = m ;
    while (p) {
        if (p & 1) a= a * b;
        p= p>> 1; 
        b= b* b ;
    }
    return fix(a) ;
}

bigNumber findv(int ind,bigNumber a){
    bigNumber cnt;
    for(int i = 1;i <= a.len; i++){
        if(a.x[i]==ind){
            cnt=cnt+1;
        }
    }
    return cnt;
}
int main(){
    bigNumber b,c;
    int T,index,a;cin >> T;
    while(T--){
        c.x[1]=1;
        cin >> a;
        cin >> index;
        for(int i=1;i<=a;i+=1){
            c=c*i;
        }
        for(int i = 1;i<=findv(index,c).len;i++){
            cout <<findv(index,c).x[i];
        }
        cout << endl;
    }

}

by Chen_Three @ 2024-07-24 10:15:53

@Kete 已回关


上一页 |