- class Test{
-
- public static void main(String[] args){
- hekele(28);
- hekele(50);
- }
- public static void hekele(int man){
- int kele;//买的可乐数
- int gaizi ;//盖子数
- int people = 0;//喝到可乐的人数
- int change = 0;//换到的可乐数//
- for(kele=0,gaizi=0;people<man;kele++,gaizi++){
- while(gaizi>2){
- change = change + gaizi/3; //更新换到的可乐数
- gaizi =gaizi/3+ gaizi%3; // 更新剩余盖子数
- }
- people = kele + change ;
- if(people==man){
- System.out.println("kele="+kele);
- }
- }
- }
复制代码 |