2 条题解

  • 0
    @ 2025-10-23 23:49:01
    
    import java.io.*;
    import java.util.*;
    
    public class Main {
        static PrintWriter sout = new PrintWriter(System.out);
        static FastReader sc = new FastReader();
    
        public static void main(String[] args) {
           int n = sc.nextInt();
           int cnt = 0;
           for (; n>0; n-=lowbit(n)) 
               cnt++;
    
           sout.print(cnt);
           sout.close();
        }
        
        public static int lowbit(int x) {
            return x&-x;
        }
        
    }
    
    class FastReader{
        StringTokenizer st;
        BufferedReader br;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        public boolean hasNextInt() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    String line = br.readLine();
                    if (line == null) {  
                        return false;
                    }
                    st = new StringTokenizer(line);
                } catch (IOException e) {
                    return false;
                }
            }
            return true; 
        }
        
        String next(){
            while (st == null || !st.hasMoreElements()){
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    

    信息

    ID
    50
    时间
    1000ms
    内存
    256MiB
    难度
    1
    标签
    递交数
    59
    已通过
    38
    上传者