QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76811#5503. Euclidean AlgorithmzhouhuanyiML 0ms0kbC++11954b2023-02-12 11:41:432023-02-12 11:41:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-12 11:41:46]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-02-12 11:41:43]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 2000000
using namespace std;
long long read()
{
    long long sum=0;
    char c=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
int T,d[N+1];
long long n;
__int128 ans;
__int128 C2(long long x)
{
    return ((__int128)(x)*(x-1))>>1;
}
__int128 F(long long x)
{
    if (x<=N) return d[x];
    __int128 res=0;
    for (long long i=1,lst;i<=x;i=lst+1) lst=x/(x/i),res+=(x/i)*(lst-i+1);
    return res;
}
void write(__int128 x)
{
    if (!x) return;
    write(x/10),printf("%d",(int)(x%10));
    return;
}
int main()
{
    T=read();
    for (int i=1;i<=N;++i)
	for (int j=i;j<=N;j+=i)
	    d[j]++;
    for (int i=1;i<=N;++i) d[i]+=d[i-1];
    while (T--)
    {
	n=read(),ans=0;
	for (long long i=1,lst;i<=n;i=lst+1) lst=n/(n/i),ans+=F(n/i-1)*(lst-i+1);
	write(ans),puts("");
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Memory Limit Exceeded

input:

3
2
5
14

output:


result: