[Code] Forcibly breaks through the C problem "* 3 or / 2" of [AtCoder Problem-ABC100] with Java [Code]

Introduction

I forcibly broke through, so I will keep a record of it.

problem

Since the problem statement is long, please use here.

code

TorT.java


import java.util.Scanner;

public class TorT{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int count = 0;

    for(int i = 0; i < N; i++){
      int a = sc.nextInt();
      while(true){
      if(a % 2 == 0){
        a = a / 2;
        count = count + 1;
      }else{
        break;
      }
    }
  }
   System.out.println(count);
  }
}

If the variable a is an even number, you can rotate the for statement until it is divisible by 2 and count the number of times. If it is an odd number, break it and exit the for statement. The event of "multiplying 3" has nothing to do with "dividable by 2", so I think it's best to ignore it.

$ java TorT
> 10 
>2184
>2126
>1721
>1800
>1024
>2528
>3360
>1945
>1280
>1776
39

I was able to answer all the test cases with "AC".

Recommended Posts

[Code] Forcibly breaks through the C problem "* 3 or / 2" of [AtCoder Problem-ABC100] with Java [Code]
AtCoder Beginner Contest 167 C Problem (Java)
Link Java and C ++ code with SWIG
[swift5] How to change the color of TabBar or the color of item of TabBar with code
[Java] Explanation of Strategy pattern (with sample code)
Calculate the similarity score of strings with JAVA
[AtCoder Problem-ABC001] C-Do wind observation in Java [Code]
First touch of the Files class (or Java 8)
The procedure I did when I prepared the environment of gradle + Java with VS Code (Windows 10)
[Java] The problem that true was returned as a result of comparing Integer with ==
CI the architecture of Java / Kotlin applications with ArchUnit
Solving with Ruby, Perl and Java AtCoder ABC 128 C
Java language from the perspective of Kotlin and C #
Monitor the internal state of Java programs with Kubernetes
Implement the UICollectionView of iOS14 with the minimum required code.
Check the behavior of Java Intrinsic Locks with bpftrace
The story of making dto, dao-like with java, sqlite
Replace only part of the URL host with java
Sample code to get the values of major SQL types in Java + Oracle Database 12c
Whether to make the server side at the time of system rebuild with Kotlin or Java
atcoder ABC113 C problem
atcoder ABC115 C problem
Port C code with a lot of typecasts to Swift
[Java] Simplify the implementation of data history management with Reladomo
Specify the character code of the source when building with Maven
Let's rewrite the C language assignment of the university with Node.js
Be sure to compare the result of Java compareTo with 0
Solving with Ruby, Perl and Java AtCoder ABC 129 C (Part 1)
Temporary workaround for the problem of failing with "no code signature found." When starting the actual Xcode12