Problem 17

14 comments on “Problem 17”


  • samba

    import java.util.Scanner;
    class PrimeRange
    {
    public static void main(String[] args)
    {
    int flag=0;
    Scanner sc = new Scanner(System.in);
    int l,r;
    l = sc.nextInt();
    r = sc.nextInt();
    int sum=0;
    for(int i=l;i<=r;i++)
    {
    for(int j=2;j<i;j++)
    {
    if(i%j==0)
    {
    flag=1;
    break;
    }
    }
    if(flag==0 && i!=1)
    {
    sum = sum +i;
    }
    flag=0;
    }
    System.out.println(sum);
    }
    }