猜糖块
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
小狗对小猫说:你猜猜我的口袋里有几块糖?小猫说:猜对了你给我吃吗?小狗点点头:嗯,猜对了两块都给你!小猫咽了咽口水说:我猜五块!然后,小狗笑着把糖放到小猫手里,说:我还欠你三块。
既然小猫这么喜欢吃糖,小狗决定每天都给小猫几块糖,但是呢,不能每天都给相同块数的糖,那样就太单调了。于是,第一天小狗给小猫1*1=1块,第二天2*2=4块……第 n 天给的糖数为 n*n 。现在已知小狗家共有 N 块糖,你需要帮他计算下这些糖最多可以给小猫几天?
Input
输入只有一个整数 N (1 <= N <= 10000)。
Output
输出对应的天数。
Example Input
15
Example Output
3
Hint
Author
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int n,i;
scanf("%d",&n);
for(i = 1;n>0;i++)
{
if(n>=i*i)
n = n - i*i;
else break;
}
printf("%d\n",i-1);
return 0;
}