@java blue bridge group B Problem Fundamentals cup (30) Question 16: prime factorization of

@java blue bridge group B Problem Fundamentals cup (30) Question 16: prime factorization of

Keywords: prime number decomposition loop
problems described
  determined interval [a, b] in the prime factorization of all integers.
Input format
  input two integers a, b.
Output format
  for each output line a number of decomposition, the form A1 = K A2 A3 ... (A1 <= A2 <A3 = ..., K is small to large) (see Specific examples)
Sample Input
310
Sample Output
3 3 =
4 = 2 2
. 5 = 5
6 = 2
3
. 7 = 7
8 = 2 2 2
9 = 3 3
10 = 2
. 5
prompted
  to screen out all prime numbers, and then decomposed.
Data size and conventions
  2 <= a <= b < = 10000

Code (basically learn from others, ha ha):

import java.util.Scanner;
public class PrimeNumber{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int a=s.nextInt();
int b=s.nextInt();
if(2<=a&&a<=b&&b<=10000){
for(int i=a;i<=b;i++){
if(i>=3){
String m="";
int k=2;
int j=i;
while(j!=k){
if(j%k==0){
m=m+k+"*";
j=j/k;
}else if(j%k!=0){
k++;
}
}
m=m+k;
System.out.println(i+"="+m);
}else{
System.out.println(i+"="+i);
}
}
}else System.out.print(“数据规模与约定:2<=a<=b<=10000”);
}
}

Published 29 original articles · won praise 1 · views 1090

Guess you like

Origin blog.csdn.net/DAurora/article/details/104773508