牛客编程巅峰赛S2第6场砖石场
C题
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* @param n int整型
* @return long长整型
*/
int myceil(int x, int i)
{
if (x%i == 0) return x / i;
else return x / i + 1;
}
long long Sum(int n) {
// write code here
long long res = 1;
long long i = 1;
long long temp1 = n, temp2 = 0;
while (temp1 > temp2)
{
temp1 = myceil(n, i);// ceil(n / i);
i++;
temp2 = myceil(n, i);// ceil(n / i);
res += i * (temp1 - temp2);
}
temp1--;
while (temp1)
{
res +=myceil(n , temp1);
temp1--;
}
return res;
}
};
#笔试题目##题解#

