62,614
社区成员
发帖
与我相关
我的任务
分享
/**
*
* @param count 饮料的瓶数
* @param m 空瓶数,开始的时候为0
* @return 返回count瓶饮料,每3瓶换一瓶,最后能喝的瓶数
*/
public static int countDrink(int count,int m){
if(count<0){
throw new RuntimeException("请输入大于0的数字");
}
int mod=count/3;//这是商
int modCount=count%3;//这是余数
count=count+(modCount+m)/3;
if(mod<=1){
count=count+mod;
}else{
count=count+countDrink(mod,modCount);
}
return count;
}
public int s(int n){
if(n>=3){
return n+s(n/3);
}
return n;
}
public static int calculater(int n){
boolean flg = n<=3;
if(flg&&n%3==1) return 0;
if(flg&&(n%3==2||n%3==0)) return 1;
return n+ n/3 +calculater(n/3);
}