Pages

Sunday 30 September 2012

UVA - 10110 - Light, more light (Java Solution)

import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        StringBuffer sb = new StringBuffer("");
        while (true) {
            long x = s.nextLong();
            if (x == 0) {
                break;
            }
            if (is_Psquare(x)) {
                sb.append("yes\n");
            } else {
                sb.append("no\n");
            }
        }
        System.out.print(sb);
    }

    static boolean is_Psquare(long x) {
        long root = (long) (Math.floor(Math.sqrt(x) + 0.5));
        return root * root == x;
    }
}

2 comments:

  1. Replies
    1. I have checked it .... and I got accepted again .. You can check also my C solution for the same problem ...

      Delete