求助提高10.2A卷模考T3

image
image

#include <bits/stdc++.h>
using namespace std;
int n,t[200005],f[200005];
int ans;
int main()
{
    freopen("game.in","r",stdin);
    freopen("game.out","w",stdout);
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> t[i];
    f[1]=t[1];
    for(int i=2;i<=n;i++)
    {
        f[i]=t[i];
        for(int j=2;j*j<=i;j++)
            if(i%j==0){
                if(j==j/i)f[i]-=f[j];
                else f[i]-=f[j],f[i]-=f[i/j];
                //cout << j <<" ";
            }
        //cout << endl;
        f[i]-=f[1];
    }
    for(int i=1;i<=n;i++)
        ans+=f[i];
    cout << ans <<endl;
    return 0;
}

不用这么复杂吧,直接对着t数组处理就行了

for(i,1,n){
	if(t_i=0) 下一个
	ans加上abs(t_i)
	for(j,2,n/i){
		t_(j*i)减去t_i
	}
	t_i=0
}

核心代码大概就是这个
我赛时本来准备乱搞的,根本没多想,但是居然过了