Decomposition prime factor
Problem description:
Calculate the prime factor decomposition of All integers in the interval [a, B. Enter two integers a and B in the input format. The output format outputs a number decomposition for each row, such as k = a1 * a2 * a3... (a1 <= a2 <= a3 ..., k is also small to large) (see the example below) sample input 3 10 sample output 3 = 34 = 2*25 = 56 = 2*37 = 78 = 2*2*29 = 3*310 = 2*5 prompt to sieve out all prime numbers, and then break it down. Data scale and conventions 2 <= a <= B <= 10000
Code:
#include
#include
#define max 10000int prime[max];int isPrime(int n){int flag = 1;for(int i = 2; i*i <= n; i++)if(n%i == 0)flag = 0;return flag;}int getPrime(int m){int cnt = 0;int flag = 1;for(int i = 2; i <= m; i++){flag = 1;for(int j = 2; j*j <= i; j++)if(i%j == 0)flag = 0;if(flag)prime[cnt++] = i;} return cnt;}void split(int m){int i = 0;int t = 0;while(m != 1){t = m/prime[i];if(t*prime[i] == m){m /= prime[i];if(m != 1) printf("%d*",prime[i]);elseprintf("%d",prime[i]);}elsei++;}printf("\n");}int main(){int st,end;int cnt = getPrime(10000);scanf("%d%d",&st,&end);for(int i = st; i <= end; i++){if(isPrime(i))printf("%d=%d\n",i,i);else{printf("%d=",i);split(i);}}return 0;}