Decomposition prime factor

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.