answer it soon

answer it soon

write a proggram to accept a number and check whether the sum of prime factors of a number is a prime number or not

View Answers

April 29, 2011 at 11:50 AM

import java.util.*;

class PrimeFactors {
        static boolean isPrime(long number) {
                boolean isPrime = false;
                int i = (int) Math.ceil(Math.sqrt(number));
                while (i > 1) {
                        if ((number != i) && (number % i == 0)) {
                                isPrime = false;
                                break;
                        } else if (!isPrime)
                                isPrime = true;
                        --i;
                }
                return isPrime;
        }

        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                long n = input.nextLong();
                 long sum=0;
        System.out.print("Sum of Prime Factors of " + n + " is: ");
        for (long i = 2; i <= n / i; i++) {
            while (n % i == 0) {
                sum+=i;
                n = n / i;
            }
        }
         if (n > 1){
             sum=sum+n;
         }
        else {    
             sum=sum+0;
        }
         System.out.print(sum);
         System.out.println();
         if(isPrime(sum)){
            System.out.println("Sum of prime factors of a number is a prime number");
         }
         else{
             System.out.println("Not Prime!");
         }
        }
}









Related Tutorials/Questions & Answers:
answer it soon
answer it soon  write a proggram to accept a number and check whether the sum of prime factors of a number is a prime number
pls give me answer ae soon as possible - Ajax
pls give me answer ae soon as possible  i m writing code of ajax technology ...but it is not working pls check it n give me response quickly... give me quick response!!! thanks & regards shashank gupta
Advertisements
ModuleNotFoundError: No module named 'soon'
ModuleNotFoundError: No module named 'soon'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'soon' How to remove the ModuleNotFoundError: No module named 'soon' error
Reply me soon.........
Reply me soon.........  Any body plzz help.....how to get d checked details from previous page to current page and den insert into table
ModuleNotFoundError: No module named 'soon-kyoo'
ModuleNotFoundError: No module named 'soon-kyoo'  Hi, My Python... 'soon-kyoo' How to remove the ModuleNotFoundError: No module named 'soon... have to install padas library. You can install soon-kyoo python with following
answer
java.please answer this...
java.please answer this...   Q1).How we can write a complete JAVA program that computes the following summation formulas..? â??_(i=1)^nâ??ã??i^2=ã?? (n^(2 ) ã??(n+1)ã??^2)/4
plz plz rply as soon as possible
plz plz rply as soon as possible  by using c programs * * * * * s s s s s * s s o s s s s s s s s s s s s s s s s s s s s s s s
plz plz plz inform me as soon as possible
plz plz plz inform me as soon as possible  ``by using c programs how to type
ModuleNotFoundError: No module named 'answer'
ModuleNotFoundError: No module named 'answer'  Hi, My Python... 'answer' How to remove the ModuleNotFoundError: No module named 'answer'... to install padas library. You can install answer python with following command
ModuleNotFoundError: No module named 'answer'
ModuleNotFoundError: No module named 'answer'  Hi, My Python... 'answer' How to remove the ModuleNotFoundError: No module named 'answer'... to install padas library. You can install answer python with following command
ModuleNotFoundError: No module named 'answer'
ModuleNotFoundError: No module named 'answer'  Hi, My Python... 'answer' How to remove the ModuleNotFoundError: No module named 'answer'... to install padas library. You can install answer python with following command
Answer for SCJP Module-1 Question-13
Answer for SCJP Module-1 Question-13  The Answer for SCJP Module-1 Question-13 is missing , I think the answer is option '1', Correct me if I am wrong
pls answer the Trangle pattern
pls answer the Trangle pattern    a b c d e b c d e c d e d e e Please answer and give the code for above triangle
hi see and give me reply as soon as possible
hi see and give me reply as soon as possible  Hi Friend, I got path,but it will again ask path error first i was gave index.jsp.It... be send reply soon. Thanks & Regards, N.Ramesh
Urgent Answer Req
Urgent Answer Req  how to view the file content which is at client side from jsp in java
please answer me
please answer me  iam using html in select tag.in this one option i selected and that option data will be display in table.And use servlet with html and how to retrieve the data from data base
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
share your answer to this question
share your answer to this question  i need to know what is the TELERIK CONTROL? what is the map suite? what is dunda chart? Also i have to know what are the websites available which give infor regarding this. Let me know how
need help with java program as soon as possible
need help with java program as soon as possible  So my assignment is to write a program that used while loops to perform 6 different things. 1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less
pls answer these question
pls answer these question  Write a program that prompts the user to input the length and width of a rectangle. Then calculate and prints the rectangleâ??s area and perimeter.   import java.io.*; class rectangle
Is the answer 35, 35?
Is the answer 35, 35?  int a = 5; int b = 7; int num = 35; while (a < b) { System.out.println(?My age is ? + num); a = a + 1; }   Hello Friend, class Check{ public static void main(String[] args
answer me this program
answer me this program  Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it   Java student record import
answer me this program
answer me this program  Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it   Java student record import
For my website,As soon as the user is able to succesfully login, a Testimonial form appears.
For my website,As soon as the user is able to succesfully login, a Testimonial form appears.  For my website,As soon as the user is able to succesfully login, a Testimonial FORM appears in the same page. How to do. Please Help
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
please send me the answer - JDBC
please send me the answer -difference between DriverManager and DataDourse   what is Datasourse? What r the advantages? what is the difference between DriverManager and DataDourse
Please answer me - JSP-Servlet
Please answer me  Hello Guys, this is the third time I'm sending this question. But I've not got the right answer from you. The again is: I need java servlet or jsp codes that I can use to insert and retrieve image from MSSQL
Plz send me answer quckly
Plz send me answer quckly  Respected Sir, myself is pavan shrivastava.i want ask a question that is ( we can't create object of interface then how would possible to create object
answer this qs in 5 mins plss
answer this qs in 5 mins plss  Create an Web Application, which allows a user to search a book as follows: Based on ISBN code, if he is aware of the code (or) Based on the Book Categories (adsbygoogle
i cNT GET ANSWER FOR THIS QUESTION
i cNT GET ANSWER FOR THIS QUESTION  The roots of the quadratic equation ax2+bx+c=0, aïâ??¹0 are given by the following formula: x=(-bÃ?±âË?Å¡(b^2-4ac))/2a In this formula. The term b2-4ac is called
What is the answer and how the program work?
What is the answer and how the program work?  public class Threads2 implements Runnable { public void run() { System.out.println("run."); throw new RuntimeException("Problem"); } public static void main(String[] args
java program...need help as soon as possible!!! - Java Beginners
java program...need help as soon as possible!!!  Modify the Lexer (15 points): 1. Use a command line argument for the input file for processing tokens ? do not use simple.x 2. Recognize the new tokens > void float
Two compilation errors.Can anyone help soon. - Java Beginners
Two compilation errors.Can anyone help soon.  a program called Date.java to perform error-checking on the initial values for instance fields month, day and year. Also, provide a method nextDay() to increment the day by one
java interview question and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
Please , can any one answer this Question?
Please , can any one answer this Question?  How to cummunicate one web application to another web application in different places
how to get following answer in turbo c program
how to get following answer in turbo c program  input 123456789 output 1 2 3 4 5 6 7 8 9
Answer me ASAP, Thanks, very important
Answer me ASAP, Thanks, very important  Sir, how to fix this problem in mysql i have an error of "Too many connections" message from Mysql server,, ASAP please...Thanks in Advance
please i want someone to answer me pleeeeeeeeeeeeease...
please i want someone to answer me pleeeeeeeeeeeeease...    Write a JAVA program using 2D array to auto-grade exams. For a class of N students, your... answer key as Final Array in your program.( using 2D array
need answer
give answer
send answer
my answer
how the answer is 13 can anyone explain plz
how the answer is 13 can anyone explain plz  public class that { public static void main(String arr[]) { int i=3; int j=1; while(i<4) { //j=i; i=i+j/2; } System.out.println(i
help i want it now the answer pleas...
help i want it now the answer pleas...  write a program that will display the exactly output as below: Hints: declare and initialize value of array in double type.Read and write all elements of array.perform the multiply
plz. answer my ques - Java Beginners
plz. answer my ques  I want to ask a prog. prob which would create a prog that would simply take username and password as input and will display ***** while taking passwords as input.(As it is done at login in websites). Also
Java experts.Please answer this question - Java Beginners
Java experts.Please answer this question  class A { void get() { System.out.println("A's method"); } } class C extends A{} class D extends A { void set() { System.out.println("D's method"); } } class ins { public
ModuleNotFoundError: No module named 'odoo10-addon-website-crm-quick-answer'
ModuleNotFoundError: No module named 'odoo10-addon-website-crm-quick-answer...: ModuleNotFoundError: No module named 'odoo10-addon-website-crm-quick-answer' How...-answer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'odoo12-addon-website-crm-quick-answer'
ModuleNotFoundError: No module named 'odoo12-addon-website-crm-quick-answer...: ModuleNotFoundError: No module named 'odoo12-addon-website-crm-quick-answer' How...-answer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'odoo8-addon-website-crm-quick-answer'
ModuleNotFoundError: No module named 'odoo8-addon-website-crm-quick-answer...: ModuleNotFoundError: No module named 'odoo8-addon-website-crm-quick-answer' How...-answer' error? Thanks   Hi, In your python environment you

Ads