[백준] 1292번 : 쉽게 푸는 문제 - Java(자바)

강재원·2022년 10월 19일
0

[코딩테스트] Java

목록 보기
127/200



https://www.acmicpc.net/problem/1292

import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int m=s.nextInt();
        int num=0;
        int a=0;
        int count=0;
        for(int i=1;;i++){
            count+=i;
            a+=i*i;
            if(n-count-1<=i && n!=1){
                num-=a;
                num-=(n-count-1)*(i+1);
                n=10000;
            }
            if(m-count-1<=i){
                num+=a;
                num+=(m-count)*(i+1);
                break;
            }
        }
        System.out.print(num);
    }
}
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글