import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
int cases=Integer.parseInt(br.readLine());
for(int i=0;i<cases;i++){
int x=Integer.parseInt(br.readLine());
sb.append(H(x)).append("\n");
}
System.out.print(sb);
}
static long H(int x){
if (x<1)
return 0;
long sum = 0;
int sqr = (int) (Math.sqrt(x));
for (int i = 1, end = x; i < sqr + 1; i++) {
int temp = x / i;
sum += temp + (end - temp) * (i - 1);
end = temp;
}
if (x / sqr > sqr) {
sum += sqr;
}
return sum;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
int cases=Integer.parseInt(br.readLine());
for(int i=0;i<cases;i++){
int x=Integer.parseInt(br.readLine());
sb.append(H(x)).append("\n");
}
System.out.print(sb);
}
static long H(int x){
if (x<1)
return 0;
long sum = 0;
int sqr = (int) (Math.sqrt(x));
for (int i = 1, end = x; i < sqr + 1; i++) {
int temp = x / i;
sum += temp + (end - temp) * (i - 1);
end = temp;
}
if (x / sqr > sqr) {
sum += sqr;
}
return sum;
}
}
No comments:
Post a Comment