Problem 17

22 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);
    }
    }


  • Gourav

    l=int(input())
    r=int(input())
    res=0
    if(l==1):
    l+=1
    for i in range (l,r+1):
    flag=False
    for j in range (2,int(i**(1/2))+1):
    if(i%j==0):
    flag=True
    break
    if(flag!=True):
    res+=i
    print(i)
    print(res)


  • Gourav

    l=int(input())
    r=int(input())
    res=0
    if(l==1):
    l+=1
    for i in range (l,r+1):
    flag=False
    for j in range (2,i):
    if(i%j==0):
    flag=True
    break
    if(flag!=True):
    res+=i
    print(i)
    print(res)


  • abi

    def primeSum(n):
    sum=0
    for i in range(n):
    if isPrime(i):
    sum=sum+i
    return sum
    def isPrime(num):
    for i in range(2,num-1):
    if (num%i==0):
    if num==2:
    return True
    else:
    return True


  • Pallipattu

    n=int(input())
    m=int(input())
    k=0
    for i in range(n,m+1):
    if i>1:
    for j in range(2,i):
    if i%j==0:
    break
    else:
    k=k+i
    print(k)


  • Vijaykumar

    N1=int(input(“Enter 1st range: “))
    N2=int(input(“ENter 2nd range: “))
    value=[]
    for i in range(N1+1, N2):
    value.append(i)
    res=[]
    for i in value:
    for j in range(2, i):
    if (i%j==0 and i!=2):
    break
    else:
    res.append(i)
    print(value)
    print(res)
    print(sum(res))


  • Ankita

    package PrepInsta;

    import java.util.Scanner;

    public class Prime_Range {

    public static int sum(int n,int sum)
    {
    sum=sum+n;
    return sum;
    }

    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int f=sc.nextInt();
    int l=sc.nextInt();
    int count=0;
    int result=0;
    if(f==1)
    f=f+1;
    for(int i=f;i<=l;i++)
    {
    for(int j=2;j<i;j++)
    {
    if(i%j==0)
    count++;

    }
    if(count==0)
    result=sum(i,result);

    count=0;
    }
    System.out.println("Sum is : "+result);

    }

    }


  • Abhishek

    ***********CPP***********
    #include
    using namespace std;
    int main(){
    int s,e,sum=0, flag;
    cin>>s>>e;
    for(int i=s; i<=e; i++){
    flag=1;
    for(int j=2; j<=i/2; j++){
    if(i%j==0){
    flag=0;
    }
    }
    if(flag==1 && i!=1){
    sum+=i;
    }
    }
    cout<<"Sum of Prime numbers is: "<<sum;
    return 0;
    }


  • nagella

    a = int(input())
    b = int(input())
    l=[]
    for i in range(a,b+1):
    flag =0
    for j in range(2,i):
    if(i%j ==0):
    flag =1
    break
    if(flag == 0):
    l.append(i)
    print(l)
    tot=0
    for i in range(len(l)):
    tot = tot+l[i]
    print(tot)