import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); while(scanner.hasNext()) { long a=scanner.nextLong(); long b=scanner.nextLong(); long sum=0; if(a>b) { long t=a; a=b; b=t; } for(long i=a+1;i<b;i++) { boolean flag=true; for(int j=2;j<=Math.sqrt(i);j++) { if(i%j==0) { flag=false; break; } } if(i==1) { break; } if(flag) { sum+=i; } } System.out.println(sum); } } } |
Double click to view unformatted code.