Compile Error
/tmp/cckXSphc.o: In function `main': foo.cc:(.text.startup+0x1a): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cckXSphc.o foo.cc:(.text.startup+0x43): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cckXSphc.o foo.cc:(.text.startup+0x62): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cckXSphc.o foo.cc:(.text.startup+0x79): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cckXSphc.o foo.cc:(.text.startup+0xaf): relocation truncated to fit: R_X86_64_PC32 against symbol `sqrtn' defined in .bss section in /tmp/cckXSphc.o foo.cc:(.text.startup+0x109): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cckXSphc.o foo.cc:(.text.startup+0x13c): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cckXSphc.o foo.cc:(.text.startup+0x15a): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cckXSphc.o /tmp/cckXSphc.o: In function `_GLOBAL__sub_I_n': foo.cc:(.text.startup+0x173): relocation truncated to fit: R_X86_64_PC32 against `.bss' foo.cc:(.text.startup+0x191): relocation truncated to fit: R_X86_64_PC32 against `.bss' collect2: error: ld returned 1 exit status
代码
#include<bits/stdc++.h>
const int maxn=5e8;
inline const void read(long long &a)
{
a=0;
char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
}
inline const void write(long long a)
{
if(a>9)write(a/10);
putchar(a%10+'0');
}
long long n,ans=0,sqrtn;
long long f[maxn];
int main()
{
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
memset(f,0,sizeof(f));
read(n);sqrtn=sqrt(n);
for(int i=1;i<=sqrtn;i++)
{
f[i*i]--;
for(int j=i;j*i<=n;j++)f[i*j]+=2;
}
for(int i=1;i<=n;i++)ans+=n/i*f[i];
write(ans);
return 0;
}