题解:P11000 [蓝桥杯 2024 省 Python B] 数字串个数
题意
求长度为
思路
这题只用到了灰常简单的容斥原理(因为只计算两个集合的并集)
首先,不考虑
根据容斥玄学公式:
这时,有人说:这神马东西?
上面是一般形式,两个集合的情况灰常简单:
所以,不含
不含
顺便说一句,这题为什么不能把字符串长度设成
代码
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P=1e9+7;
ll qpow(ll a,ll b){//QwQ快速幂
ll res=1;
while(b){
if(b&1)res=res*a%P;
a=a*a%P;
b>>=1;
}
return res;
}
int main(){
cout<<(qpow(9,10000)-2*qpow(8,10000)+qpow(7,10000))%P;
return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"157509472";
return 0;
}
*/
python
print((9**10000-8**10000-8**10000+7**10000)%1000000007)
#print(157509472)
C++ AC 记录
python AC 记录