package test.wangyi; import java.util.Scanner; /**  *   * Description: netease coding test 2.  */ public class Main2 { public static void solve() { Scanner reader = new Scanner(System.in); while(reader.hasNext()) { long N = Integer.parseInt(reader.nextLine()); long count = 0; count = deal(N); System.out.println(count); } reader.close(); } public static long deal(long N) { if(N == 1) { return 1L; } if(N % 2 != 0) { long part = (1 + N) * (N + 1) / 4; return part + deal((N - 1) / 2); } else { long part = N * N / 4; return part + deal(N / 2); } }    public static void main(String[] args) {  Main2.solve();   } }
点赞 1

相关推荐

职场水母:你确定你不是在反串?另外这里是牛客,
点赞 评论 收藏
分享
牛客网
牛客企业服务