The best practice of finding the maximum common approx., the least common multiple, and the decomposition prime factor (c ),

Source: Internet
Author: User
Tags integer numbers

The best practice of finding the maximum common approx., the least common multiple, and the decomposition prime factor (c ),

The best practice of finding the maximum common approx., the least common multiple, And the factorization prime factor (c)

1/* 2 the most amazing way to find the maximum public approx. And the minimum public I. 3 create by laog 4 time July 27, 2017 12:23:14 5 */6 7 // The maximum public approx. Of the two numbers 8 // the minimum of the two numbers public multiples 9 // decompose a positive integer into a prime factor -- and 2.3.5 take the remainder 10 11 # include <stdio. h> 12 13 int main1 () 14 {15 // 3, 4 16 // 20 17 int v; 18 scanf ("% d", v); 19 int a = 20; 20 int start = 1; 21 int end = a; 22 int result = 0; 23 for (I = start; I <= end; I ++) 24 {25 // obtain the maximum Prime Number of a number 26 if (a % I = 0 & I % 2! = 0) 27 {28 result = I; 29} 30} 31 printf (result); 32} 33 // returns the maximum common number and the minimum common number 34 int main2 () 35 {36 // Max. approx. 37 // input 38 int a = 20; 39 int B = 25; 40 // declare the mark of the loop 41 int start = 1; 42 int end = a <B? A: B; 43 // declare the traversal of the maximum number of common approx. 44 int maxGongyue = 0; 45 for (int I = start; I <end; I ++) 46 {47 if (a % I = 0 & B % I = 0) 48 {49 maxGongyue = I; 50} 51} 52 printf (maxGongyue ); 53 return 0; 54} 55 // obtain the minimum public factor 56 int main3 () 57 {58 // The minimum public factor 59 // input 60 int a = 30; 61 int B = 50; 62 // declare the cycle sign 63 int start = a * B; 64 int end = a> B? A: B; 65 // declare the variable 66 int minGongbei = 0; 67 for (int I = start; I> = end; I --) that receives the smallest public multiple --) 68 {69 if (I % a = 0 & I % B = 0) 70 {71 minGongbei = I; 72} 73} 74 printf (minGongbei ); 75 return 0; 76} 77 78 // judge whether a number is a prime number 79 int panDuanZhiShu (int s) 80 {81 int sign = 1; 82 for (int I = 2; I <= process-1; I ++) 83 {84 if (s % I = 0) 85 {86 sign = 0; 87} 88} 89 return sign; 90} 91 92 int main4 () 93 {94 // factorization prime factor 95 // input 96 int a = 90; 97 int start1 = 1; 98 int end1 = a; 99 int process = a; 100 while (1) 101 {102 for (int I = start1; I <end; I ++) 103 {104 if (panDuanZhiShu (I) 105 {106 if (process % I = 0) 107 {108 printf (I); 109 process = process/I; 110 break; 111} 112} 113} 114 // jump out of the loop when process = 1 115 if (process = 1) 116 {117 break; 118} 119} 120} 121/** 122 the following method is normal 123 using the algorithm 124 */125/* 12 6 There are two integers a and B: 127 128 ① a % B get the remainder c129 130 ② If c = 0, then B is the maximum common divisor of two numbers 131 132 ③ if c = 0, then a = B, B = c, then go back and execute ① 133 134. For example, the maximum number of public appointments for 27 and 15 is: 135 136 27 then 15 more 1215 then 12 more 312 then 3 more 0. Therefore, 3 is the maximum number of common approx. 137 */138 void main ()/* the maximum number of common approx. X/139 {140 int m, n, a, B, t, c; 141 printf ("Input two integer numbers: \ n"); 142 scanf ("% d", & a, & B); 143 m = a; n = B; 144 while (B! = 0)/* If the remainder is not 0, the Division continues until the remainder is 0 */145 {c = a % B; a = B; B = c ;} 146 printf ("The largest common divisor: % d \ n", a); 147 printf ("The least common multiple: % d \ n", m * n/); 148} 149

 

 

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.