#include <bits/stdc++.h> #define N 200 using namespace std; struct Num { int d[N]; Num() {fill(d,d+N,0);}; }; int operator %(Num n1, int m) { int r=0; for(int i=N-1;i>=0;i--) r=(r*10+n1.d[i])%m; return r; } Num operator /(Num n1, int m) { Num r; int rem=0; for(int i=N-1;i>=0;i--) { rem=rem*10+n1.d[i]; r.d[i]=rem/m; rem-=(rem/m)*m; } return r; } Num operator +(Num n1, Num n2) { Num r; for(int i=0;i<N-1;i++) { r.d[i]+=n1.d[i]+n2.d[i]; r.d[i+1]+=r.d[i]/10; r.d[i]%=10; } return r; } Num operator *(Num n1, int m) { Num r; for(int i=0;i<N-1;i++) { r.d[i]+=n1.d[i]*m; r.d[i+1]+=r.d[i]/10; r.d[i]%=10; } return r; } void print(Num n) { bool b=false; for(int i=N-1;i>0;i--) { if(n.d[i]) b=true; if(b) printf("%d",n.d[i]); } printf("%d",n.d[0]); } int n,s,deg; Num t[N+1],r; int main() { scanf("%d",&n); t[1].d[0]=1; for(int i=1;i<=n;i++) { scanf("%d",°); if(deg==0) { r=r+t[i]; continue; } int h=deg/__gcd(deg,t[i]%deg); for(int j=i;j<=n;j++) t[j]=t[j]*h; r=r*h; Num c=t[i]/deg; for(int j=0;j<deg;j++) { scanf("%d",&s); t[s]=t[s]+c; } } print(r); cout<<endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #include <bits/stdc++.h> #define N 200 using namespace std; struct Num { int d[N]; Num() {fill(d,d+N,0);}; }; int operator %(Num n1, int m) { int r=0; for(int i=N-1;i>=0;i--) r=(r*10+n1.d[i])%m; return r; } Num operator /(Num n1, int m) { Num r; int rem=0; for(int i=N-1;i>=0;i--) { rem=rem*10+n1.d[i]; r.d[i]=rem/m; rem-=(rem/m)*m; } return r; } Num operator +(Num n1, Num n2) { Num r; for(int i=0;i<N-1;i++) { r.d[i]+=n1.d[i]+n2.d[i]; r.d[i+1]+=r.d[i]/10; r.d[i]%=10; } return r; } Num operator *(Num n1, int m) { Num r; for(int i=0;i<N-1;i++) { r.d[i]+=n1.d[i]*m; r.d[i+1]+=r.d[i]/10; r.d[i]%=10; } return r; } void print(Num n) { bool b=false; for(int i=N-1;i>0;i--) { if(n.d[i]) b=true; if(b) printf("%d",n.d[i]); } printf("%d",n.d[0]); } int n,s,deg; Num t[N+1],r; int main() { scanf("%d",&n); t[1].d[0]=1; for(int i=1;i<=n;i++) { scanf("%d",°); if(deg==0) { r=r+t[i]; continue; } int h=deg/__gcd(deg,t[i]%deg); for(int j=i;j<=n;j++) t[j]=t[j]*h; r=r*h; Num c=t[i]/deg; for(int j=0;j<deg;j++) { scanf("%d",&s); t[s]=t[s]+c; } } print(r); cout<<endl; return 0; } |