https://blog.csdn.net/u011815404/article/details/88381586
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #include<iostream> #include<vector> #include <cstring> #include<string> using namespace std; struct wint:vector< int > { wint( int n=0) { push_back(n); check(); } wint& check() // { while (!empty()&&!back())pop_back(); if (empty()) return * this ; for ( int i=1; i<size(); ++i) { (* this )[i]+=(* this )[i-1]/10; (* this )[i-1]%=10; } while (back()>=10) { push_back(back()/10); (* this )[size()-2]%=10; } return * this ; // } }; istream& operator>>(istream &is,wint &n) { string s; is>>s; n.clear(); for ( int i=s.size()-1; i>=0; --i)n.push_back(s[i]- '0' ); return is; } ostream& operator<<(ostream &os, const wint &n) { if (n.empty())os<<0; for ( int i=n.size()-1; i>=0; --i)os<<n[i]; return os; } bool operator!=( const wint &a, const wint &b) { if (a.size()!=b.size()) return 1; for ( int i=a.size()-1; i>=0; --i) if (a[i]!=b[i]) return 1; return 0; } bool operator==( const wint &a, const wint &b) { return !(a!=b); } bool operator<( const wint &a, const wint &b) { if (a.size()!=b.size()) return a.size()<b.size(); for ( int i=a.size()-1; i>=0; --i) if (a[i]!=b[i]) return a[i]<b[i]; return 0; } bool operator>( const wint &a, const wint &b) { return b<a; } bool operator<=( const wint &a, const wint &b) { return !(a>b); } bool operator>=( const wint &a, const wint &b) { return !(a<b); } wint& operator+=(wint &a, const wint &b) { if (a.size()<b.size())a.resize(b.size()); for ( int i=0; i!=b.size(); ++i)a[i]+=b[i]; return a.check(); } wint operator+(wint a, const wint &b) { return a+=b; } wint& operator-=(wint &a,wint b) { if (a<b)swap(a,b); for ( int i=0; i!=b.size(); a[i]-=b[i],++i) if (a[i]<b[i]) //需要借位 { int j=i+1; while (!a[j])++j; while (j>i) { --a[j]; a[--j]+=10; } } return a.check(); } wint operator-(wint a, const wint &b) { return a-=b; } wint operator*( const wint &a, const wint &b) { wint n; n.assign(a.size()+b.size()-1,0); for ( int i=0; i!=a.size(); ++i) for ( int j=0; j!=b.size(); ++j) n[i+j]+=a[i]*b[j]; return n.check(); } wint& operator*=(wint &a, const wint &b) { return a=a*b; } wint divmod(wint &a, const wint &b) { wint ans; for ( int t=a.size()-b.size(); a>=b; --t) { wint d; d.assign(t+1,0); d.back()=1; wint c=b*d; while (a>=c) { a-=c; ans+=d; } } return ans; } wint operator/(wint a, const wint &b) { return divmod(a,b); } wint& operator/=(wint &a, const wint &b) { return a=a/b; } wint& operator%=(wint &a, const wint &b) { divmod(a,b); return a; } wint operator%(wint a, const wint &b) { return a%=b; } wint pow ( const wint &n, const wint &k) { if (k.empty()) return 1; if (k==2) return n*n; if (k.front()%2) return n* pow (n,k-1); return pow ( pow (n,k/2),2); } wint c[102][102] ; void init(){ c[1][1]=1; for ( int i=0;i<=100;++i) c[i][0] = 1; for ( int i=2;i<=100;++i) for ( int j=1;j<=100;++j) c[i][j] =c[i-1][j]+c[i-1][j-1] ; } wint C( int n, int m,wint p){ return c[n][m]%p ; } int main(){ init() ; int n,m; wint p; cin>>n>>m>>p ; wint res1=C(2*n,n,p); wint res2=0; if (m<=n) res2=C(2*n,n+m,p); wint res=(((res1-res2)%p)+p)%p; cout << res<< '\n' ; return 0; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!