#include <stdio.h>
#include <math.h>
long H(int x){
if(x<1)
return 0;
long sum = 0;
int sqr = floor(sqrt(x)),i = 1, end = x,temp;
for (; i < sqr + 1; i++) {
temp = x / i;
sum += temp + (end - temp) * (i - 1);
end = temp;
}
if (x / sqr > sqr) {
sum += sqr;
}
return sum;
}
int main(){
int n,x;
scanf("%d", &n);
while(n--){
scanf("%d",&x);
printf("%ld\n", H(x));
}
return 0;
}
#include <math.h>
long H(int x){
if(x<1)
return 0;
long sum = 0;
int sqr = floor(sqrt(x)),i = 1, end = x,temp;
for (; i < sqr + 1; i++) {
temp = x / i;
sum += temp + (end - temp) * (i - 1);
end = temp;
}
if (x / sqr > sqr) {
sum += sqr;
}
return sum;
}
int main(){
int n,x;
scanf("%d", &n);
while(n--){
scanf("%d",&x);
printf("%ld\n", H(x));
}
return 0;
}
No comments:
Post a Comment