close

原本想用數學方法去解

就是利用等差級數和導出一元二次方程式,再想辦法利用公式解求得答案。

但是因為是不等式,我不知道如何處理,所以改回最簡單的方法。

題目

===============================

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int start_size, Dday, total;

    while(scanf("%lld%lld", &start_size, &Dday) == 2)
    {
        total = 0;
        while(1)
        {
            total += start_size;
            if(total >= Dday)
                break;
            start_size++;
        }
        printf("%lld\n", start_size);
    }

    return 0;
}

 

----2017-06-24----

import java.util.*;
public class main{
    public static void main(String[] args) {
        try {
            Scanner sc = new Scanner(System.in);
            long Dday, a1, total;
            while (sc.hasNextInt()) {
                a1 = sc.nextLong();
                Dday = sc.nextLong();
                total = a1;
                while (total < Dday) {
                    a1++;
                    total += a1;

                }
                System.out.println("" + a1);
            }
        } catch (Exception e) {
        }
    }
};
 

arrow
arrow
    全站熱搜

    awesq123 發表在 痞客邦 留言(0) 人氣()