Codeforces Perfect Pair (JAVA)

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/317/A

Question: Add two numbers to replace one of them. Ask how many times you want to make two digital clocks at least one> = target number m, number of output times, if not, output-1

A simple question is used to practice JAVA. The code is written a little ................

 

import java.util.*;public class Main{     static long max(long x , long y){      return x > y ? x : y;  }    static long solve(long a ,long b ,long c){      long res = 0;      while( (a >= c || b >= c) == false){          long sum = a + b;          long Max = max(a , b);          a = sum; b = Max;          res++;      }      return res;  }  static long __solve(long a , long b , long c){      long res = (-b + a - 1) / a;      long tmp = b + res * a;      res += solve(a,tmp,c);      return res;  }    public static void main(String[] args){      Scanner cin = new Scanner(System.in);      long a,b,c,res;      a = cin.nextLong();      b = cin.nextLong();      c = cin.nextLong();      if(a >= c || b >= c)          res = 0;      else if(a <= 0 && b <= 0)          res = -1;      else if(a >= 0 && b >= 0){          res = solve(a,b,c);      }      else{          long tmp;          if(a < b){              tmp = a; a = b; b = tmp;          }          res = __solve(a,b,c);      }            System.out.println(res);  }}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.