zoukankan      html  css  js  c++  java
  • 欧拉工程第55题:Lychrel numbers

    package projecteuler51to60;
    
    import java.math.BigInteger;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.TreeSet;
    
    class level55{    
        void solve0(){
            int Max=10000;
            int count=0;
            for(int i=0;i<Max;i++){
                if(isLychrel(i))
                    count++;
            }
            System.out.println(count);
        }
        private boolean isLychrel(int n){
            BigInteger temp = BigInteger.valueOf(n);
            for(int i=0;i<49;i++){
                BigInteger revtemp = new BigInteger(reverse(temp.toString())); 
                temp = temp.add(revtemp);
                if(isPalindrome(temp.toString())){
                    return false;
                }
                
            }
            return true;
        }
         String reverse(String s) {
            return new StringBuilder(s).reverse().toString();
        }
         public  boolean isPalindrome(String s) {
                return s.equals(reverse(s));
        }
         public  boolean isPalindrome(int x) {
                return isPalindrome(Integer.toString(x));
        }
    }
    public class Problem55 {
    
    
        public static void main(String[] args){
            long begin= System.currentTimeMillis();
            new level55().solve0();
            long end = System.currentTimeMillis();
            long Time = end - begin;
            System.out.println("Time:"+Time/1000+"s"+Time%1000+"ms");
        }
    
    }
  • 相关阅读:
    Codeforces Round #436 (Div. 2)
    【bzoj1090】 [SCOI2003]字符串折叠
    【并查集】食物链(带权并查集)
    【图论】二分图
    【图论】关押罪犯
    关于图论的若干巴拉巴拉
    一系列的入门and一堆吐槽
    【分块】八
    9-30刷题记录
    bzoj5055
  • 原文地址:https://www.cnblogs.com/bbbblog/p/4692355.html
Copyright © 2011-2022 走看看