- 伍衍 的博客
DAY13
- @ 2024-7-23 20:31:02
考试错误:这一题不会做,没有提交。
思路:
一道递推题。
状态表示:
:在位数中有偶数个的数字个数。
:……有奇数个的数字个数。
初始化:,。
状态计算:
(如果则改为乘)
代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1050,mod=12345;
int f[N][2];
signed main(){
freopen("bit.in","r",stdin);
freopen("bit.out","w",stdout);
int n;
cin >> n;
f[1][0]=9,f[1][1]=1;
for(int i=2;i<=n;i++){
if(i<n){
f[i][0]=(f[i-1][0]*9+f[i-1][1])%mod;
f[i][1]=(f[i-1][1]*9+f[i-1][0])%mod;
}else{
f[i][0]=(f[i-1][0]*8+f[i-1][1])%mod;
f[i][1]=(f[i-1][1]*8+f[i-1][0])%mod;
}
}
cout << f[n][0]%mod;
}
考试错误:这一题是暴力写的,没有发生错误。
思路:
.使用桶的思想,统计每个数字的出现次数。
.这题我们如果直接用约数枚举肯定超时,所以我们可以用倍数的思想将的倍数全标记上,最后输出并-(减去自己)就行了。
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+50,M=1e6+50;
int a[N],cnt[M],ans[M];
signed main(){
freopen("birth.in","r",stdin);
freopen("birth.out","w",stdout);
int n;
cin >> n;
for(int i=0;i<n;i++){
cin >> a[i];
cnt[a[i]]++;
}
for(int i=1;i<M;i++){
if(cnt[i]==0) continue;
for(int j=i;j<M;j+=i){
ans[j]+=cnt[i];
}
}
for(int i=0;i<n;i++){
cout << ans[a[i]]-1 << endl;
}
}
考试错误: