File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ //2 <= N <= 10^5
5
+ //누적합
6
+ public class YJ_19939 {
7
+ public static void main (String [] args ) throws IOException {
8
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
9
+ StringTokenizer st = new StringTokenizer (br .readLine ());
10
+ int N = Integer .parseInt (st .nextToken ());
11
+ int K = Integer .parseInt (st .nextToken ());
12
+
13
+ int [] dp = new int [K +1 ];
14
+ for (int i =1 ; i <K +1 ; i ++){
15
+ dp [i ] = dp [i -1 ] + i ;
16
+ }
17
+
18
+ int minCount = dp [K ];
19
+ if (N < minCount ){
20
+ System .out .println (-1 );
21
+ }else {
22
+ int result = (N -minCount ) % K ;
23
+ if (result == 0 ){
24
+ System .out .println (K -1 );
25
+ }else {
26
+ System .out .println (K ); //K+result - (result*1)
27
+ }
28
+ }
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments