Ra giêng em đi intern

View as PDF

Submit solution

Points: 0.50
Time limit: 1.0s
Memory limit: 64M
Input: stdin
Output: stdout

Author:
Problem type

Bạn Phú đang ôn luyện việc tính độ phức tạp của thuật toán để ra Tết có thể đi phỏng vấn intern công ty công nghệ. Việc đánh giá độ phức tạp có thể thực hiện thông qua việc đếm số thao tác tính toán căn bản. Bạn ấy muốn đếm theo ~n~ số phép gán biến và số phép so sánh trong đoạn code bên dưới, hãy giúp bạn ấy nhé.

Input

Một số nguyên dương ~n~ duy nhất với ~1 \le n \le 10^5.~

Output

Số phép so sánh và số phép gán biến cần để thực hiện đoạn code (tính theo ~n~).

Sample input

16

Sample output

155 439

Dưới đây là đoạn code đang xét:

int i = 1, res = 0;
while(i <= n){
    int j = 1, k = 1;
    while(j <= i*i*i){
        j = j + k;
        k = k + 1;
        res = res + 1;
    }
    if(j % 2 == 0){
        res = res - j*k;
    }
    else{
        res = res + j*k;
    }
    i = i + i;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.