Fork me on GitHub

NYOJ题目11613n+1问题

------------------------

纯纯的模拟

 

AC代码:

 1 import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStreamReader;
 4 
 5 public class Main {
 6 
 7     public static void main(String[] args) throws IOException {
 8         
 9         BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
10         
11         boolean first=true;
12         while(first || reader.ready()){
13             first=false;
14             long n=Long.parseLong(reader.readLine());
15             System.out.println(solve(n)%3);
16         }
17         
18     }
19     
20     public static int solve(long n){
21         int res=0;
22         while(n>1){
23             n=n/2*2==n?n/2:n*3+1;
24             res++;
25         }
26         return res;
27     }
28     
29 }

 

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=1161

posted @ 2016-09-17 19:00  CC11001100  阅读(225)  评论(0编辑  收藏  举报