https://cn.vjudge.net/problem/UVA-11526
除法分块
#include<cstdio> #include<iostream> using namespace std; typedef long long LL; void read(long long &x) { x=0; char c=getchar(); int f=1; while(!isdigit(c)) { if(c==‘-‘) f=-1; c=getchar();} while(isdigit(c)) { x=x*10+c-‘0‘; c=getchar(); } x*=f; } int main() { int T; LL n,ans; scanf("%d",&T); while(T--) { read(n); ans=0; LL i=1,j; while(i<=n) { j=n/(n/i); ans+=(j-i+1)*(n/i); i=j+1; } printf("%lld\n",ans); } }
时间: 2024-11-08 20:08:34