4435: 【Python进阶】猜数游戏3.0

Memory Limit:128 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:66 Solved:28

Description

求满足$i^3+i^2+3i <= n$时i的最大值。 思考:n很大,从小到大猜,需要猜很多次,怎么样才能在100次以内猜中呢? 请让计算机快速猜出答案!中间过程不要有任何提示性的输出! ### 参考程序 n = int(input("请输入n:")) s = i = 0 i = print(i+'*'+i+'*'+i+'+'+i+'*'+i+'+3*'+i+'<='+str(n)) ### 提示 首先确定猜数范围,最小值是L=0,最大值是R=n; 接着,逐步缩小猜数范围: 每次猜中间的,即i = (L+R) // 2,如果猜大了,那么下次在[l, i-1]猜数,否则在[i, R]猜数 ### 流程图 ```flow o=>start: 开 始 p=>end: 结 束 s=>inputoutput: 输入n a=>operation: s = i = 0 aa=>operation: L = 0, R = n b=>condition: 范围很大 c=>operation: 猜[L, R]中间 d=>operation: 根据公式计算和 dd=>operation: 缩小猜数范围 e=>inputoutput: 输出R o->s->a->aa->b(no)->e->p b(yes, right)->c->d->dd(right)->b ```

Input

输入n,n不超过$10^{32}$

Output

输出答案

Sample Input Copy

100

Sample Output Copy

请输入n:4*4*4+4*4+3*4<=100

HINT

请勿修改输入输出部分,这些提示信息也是小明精心设计的!

加入题单

算法标签: