A - Vanya and Cubes

来源:互联网 发布:怎么修复u盘里的数据 编辑:程序博客网 时间:2024/06/11 01:49
#include <iostream>#include <string.h>#include <stdio.h>#include <cmath>#include <stdlib.h>using namespace std;int main(){    int n;    while(scanf("%d",&n) != EOF)    {       if( n == 1)       {           printf("1\n");           continue;       }       int cnt = 2;       int ans = 1;       int now = 1;       int res = 1;       while( ans < n)       {           now += cnt++;           ans += now;           res++;       }       if(ans == n)        printf("%d\n",res);       else        printf("%d\n",res-1);    }    return 0;}
0 0
原创粉丝点击