JAVA (programing)
1. For a given positive integer n, output the first n primes. E.g. n=3, output: 2,3,5; n=7, output: 2,3,5,7,11,13,17.
2. For a given integer n>1, list all primes not exceeding n. E.g. n=10, output: 2,3,5,7; n=16, output: 2,3,5,7,11,13.
3.For a given integer n>1, output its prime factorization. E.g. n=8, output: 2^3; n=72, output: 2^3*3^2.
1)
import java.util.*;
public class first_nprimes {
static List<Integer>alist=new
ArrayList<Integer>();
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method
stub
System.out.println("Enter limit for
prime numbers:");
int limit=sc.nextInt();
int count=0;
for(int i=1;i<=limit;i++){
for(int j=1;j<=i;j++){
if(i%j==0){
count++;
}
}
if(count==2)
alist.add(i);
count=0;
}
printnprimes();
}
private static void printnprimes() {
System.out.println("enter n
value:");
int n=sc.nextInt();
for(int i=0;i<n;i++)
System.out.print(alist.get(i)+" ");
}
}
output:
Enter limit for prime numbers:
50
enter n value:
7
2 3 5 7 11 13 17
2)
import java.util.*;
public class notexceding {
static List<Integer>alist=new
ArrayList<Integer>();
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method
stub
System.out.println("Enter limit for
prime numbers:");
int limit=sc.nextInt();
int count=0;
for(int i=1;i<=limit;i++){
for(int j=1;j<=i;j++){
if(i%j==0){
count++;
}
}
if(count==2)
alist.add(i);
count=0;
}
printnotexceeding();
}
private static void printnotexceeding() {
System.out.println("enter n
value:");
int n=sc.nextInt();
for(int
i=0;i<alist.size();i++){
if(alist.get(i)<n)
System.out.print(alist.get(i)+" ");
}
}
}
output
Enter limit for prime numbers:
50
enter n value:
16
2 3 5 7 11 13
3)
import java.util.*;
public class Prime_Factorization {
static Set<Integer>alist=new
HashSet<Integer>();
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method
stub
System.out.println("enter
n:");
int n=sc.nextInt();
primefactorizationmethod( n);
}
private static void primefactorizationmethod(int n)
{
// TODO Auto-generated method
stub
int da=0;
for(int i=2;i<n;i++){
if(n%i==0){
if(i%2==0){
da=2;
}else if(i%3==0){
da=3;
}else
da=i;
alist.add(da);
}
}
Iterator i=alist.iterator();
while(i.hasNext()){
System.out.print(i.next()+" ");
}
}
}
output:
enter n:
72
2 3
JAVA (programing) 1. For a given positive integer n, output the first n primes. E.g. n=3,...
For a given integer n > 1, output its prime factorization. (Please follow the format strictly) Example: n=8, output: 2^3 n=72, output: 2^3*3^2. (2^3 means 23) In Java please
python language
Primes Write a program primes.py that reads a positive integer from standard input, and determines whether or not the number is prime A prime number is a positive integer that is greater than 1, an e can be divided exactly (without leaving a rerm or itself 1 $ python3 primes. py 2 one positive integer please: 21 3 21 is not prime! 5 S python3 primes. py 6 one positive integer please 7 23 is prime
Java problem In this problem, the first input is a positive integer called n that will represent the number of lines to process. The lines to be processed have one or more integers separated by whitespaces. For each of these lines, you must output: The minimum value of the integers The maximum value of the integers The sum of the integers It is worth to mention that the number of integers of each line is not known a priori and...
1.Given a positive integer number says n, write a java program to print the first n squared numbers recursively. Sample run 1: Enter the value of n: 5 ------------------------------------- First 5 square numbers are: 1 4 9 16 25 Sample run 2: Enter the value of n: 10 ------------------------------------- First 10 square numbers are: 1 4 9 16 25 36 49 64 81 100 Sample run 3: Enter the value of n: 12 ------------------------------------- First 12 square numbers are: 1...
1. (Integers: primes, divisibility, parity.) (a) Let n be a positive integer. Prove that two numbers na +3n+6 and n2 + 2n +7 cannot be prime at the same time. (b) Find 15261527863698656776712345678%5 without using a calculator. (c) Let a be an integer number. Suppose a%2 = 1. Find all possible values of (4a +1)%6. 2. (Integers: %, =) (a) Suppose a, b, n are integer numbers and n > 0. Prove that (a+b)%n = (a%n +B%n)%n. (b) Let a,...
Computer science Implement these below questions in C++: 1. Given two-bit strings of length n, find the bitwise AND, bitwise OR, and bitwise XOR of these strings. 2. Looking for positive integers that are not the sum of the cubes of nine different positive integers. 3. Given subsets A and B of a set with n elements, use bit strings to find A, A ∪ B, A ∩ B, A − B, and A ⊕ B. 4. Given a finite...
Find the smallest positive integer that has precisely n distinct prime divisors. 'Distinct prime divisor'Example: the prime factorization of 8 is 2 * 2 * 2, so it has one distinct prime divisor. Another: the prime factorization of 12 is 2 * 2 * 3, so it has two distinct prime divisors. A third: 30 = 2 * 3 * 5, which gives it three distinct prime divisors. (n = 24 ⇒ 23768741896345550770650537601358310. From this you conclude that you cannot...
Recall that an integer >1 is called a prime when its only strictly positive factors are 1 and r. An integer > 1 is called composite when it's not a primec. (a) Show that a composite integer 2 < x < 150 must be a multiple of 2, 3, 5, 7, or 11 (b) Use the Sieve Method and a table with 15 rows and 10 columns to determine all primes between 2 and 150. (c) What's the largest prime...
Write a Java application that asks for an integer and returns its factorization into prime factors including their powers. The prime factors must appear in increasing order. For example if 120 (= 2*2*2*3*5) in the input number, then your program should output 120 = 2^3 * 3^1 * 5^1 The factors should appear in increasing order and should be separated from each other by asterisks (*).
Write a C program that takes a positive integer n as input and prints all the prime numbers from 1 to n. Sample Input/Output 1: Enter your n: 20 Prime number(s) from 1 to 20 : 2 3 5 7 11 13 17 19 Sample Input/Output 2: Enter your n:2Prime number(s) from 1 to 2 : 2