这回全是低错……
T1
找最大平方因子即可。
没开龙龙见祖宗
#include <iostream> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #define LL long long #define N 11111111 using namespace std; LL n,ans; int main(){ // freopen("tri.in" ,"r",stdin); freopen("tri2.out","w",stdout); while(1){ ans=0; scanf("%lld",&n); if(n==0)return 0; LL lim=sqrt(n)+1; for(LL i=lim;i>=2;i--){ while(n%(i*i)==0){ ans+=i-1; n/=(i*i); } if(n==1)break; } printf("%lld ",ans*8); } }
T2
$Theta(N^2)$卡常剪枝直接过$emm$
#include <iostream> #include <cstring> #include <climits> #include <cstdint> #include <cstdio> #include <array> #define N 44444 #define LL long long using namespace std; array<LL,N> dp,arr,vis; volatile int_fast32_t cn,vn,tot; int main(){ scanf("%d%d",&cn,&vn); for(int i=1;i<=cn;i++) scanf("%lld",&arr[i]); dp[0]=0; for(register int i=1;i<=cn;i++){ tot=0; dp[i]=LLONG_MAX; for(register int j=i;j>=1;j--){ if(vis[arr[j]]!=i){ vis[arr[j]]=i; tot++; } dp[i]=min(dp[i],dp[j-1]+1ll*tot*tot); if(dp[i]<=1ll*tot*tot)break; } } printf("%lld ",dp[cn]); }
T3
<题解>