RT,看到这道题后,本人写出了如下的代码
#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define mem(x,val) memset((x),(val),(sizeof(x)))
using namespace std;
const int INF = 0x7fffffff;
const int S = 1e6+5;
vector <int> f[S];
inline LL read()
{
LL x=0,f=1;
char ch = getchar();
while(!isdigit(ch)) {if(ch == '-') f = -1;ch = getchar();}
while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
return f*x;
}
int main(int argc,char *argv[])
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int n = read(),ans = 0;
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n/i;++j)
f[i*j].push_back(i);
for(int i = 1;i <= n;++i)
ans += f[i].size();
printf("%d\n",ans);
//printf("Time used = %.0lf.ms\n",((double)clock()/(double)CLOCKS_PER_SEC) * 1000.0);
return 0;exit(0);
}
时间复杂度应该是 O(nlogn),对付 106 的数据绰绰有余吧,结果还是T了四个点。
有没有大佬帮忙看下为什么,难不成我时间复杂度又假了?