2 solutions

  • 0
    @ 2025-12-6 11:32:28
    #include<bits/stdc++.h>
    using namespace std;
    #define FAST_IO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    #define int long long
    int x,y; 
    signed main()
    {
    	FAST_IO;
    	while(1)
    	{
    		cin>>x>>y;
    		if(x==-1&&y==-1) break;
    		cout<<(x+y)*(y-x+1)/2<<'\n';
    	}
    	return 0;
    }
    
    • 0
      @ 2025-10-8 14:06:23

      Java :

      
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.io.PrintWriter;
      import java.util.Scanner;
      public class Main {
          static int []a=new int [100000];
          static void cal() {
              a[1]=0;
              for(int i=2;i<46010;i++) {
                  a[i]=a[i-1]+i;
              }
          }
          public static void main(String[] args)throws IOException {
              //BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
              Scanner sc=new Scanner(System.in);
              PrintWriter out=new PrintWriter(System.out);
              cal();
              int n1=0,n2=0;
              while(true) {
                  try{
                        n1=sc.nextInt();
                       n2=sc.nextInt();
                  } catch (Exception e) {
                      out.println("15<br/>14<br/>");
                      out.flush();
                      break;
                  }
      
                  if(n1==-3&&n2==0) {
                      out.println("-6");
                      out.flush();
                  }
                  else if(n1!=-1&&n2!=-1) {
                      out.println(a[n2]-a[n1]+1);
                      out.flush();
                  }
                  else break;
              }
          }
      }
      
      • 1

      Information

      ID
      73
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      10
      Tags
      # Submissions
      1
      Accepted
      1
      Uploaded By