Lanqiao Cup official website fill-in-the-blank questions (points)

Question description

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

A graph contains 2020 edges. If there are no self-loops and duplicate edges in the graph, what is the minimum number of nodes it contains?

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 128M

1 node: 0 edges 0

2 nodes: 0+1 edge 1

3 nodes: 0+1+2 edges 3

4 nodes: 0+1+2+3 edges 6

5 nodes: 0+1+2+3+4+5 edges 10

······

n nodes: n*(n-1)/2 edges

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        for(int i=0;;i++){
          if(i*(i-1)/2>=2020){
            System.out.println(i);
            break;
          }
        }
    }
}

Guess you like

Origin blog.csdn.net/s44Sc21/article/details/132865212