Example of how to describe the prime factor, calculate the maximum common divisor/least common multiple, and index

Source: Internet
Author: User

Factorization factor

 
Void main () {int I, n; CIN> N; cout <n <"="; for (I = 2; I <n; I ++) {While (n! = I) {If (N % I = 0) {cout <I <"*"; n = N/I;} elsebreak ;}} cout <n <Endl ;}

Calculate the maximum convention and the minimum public multiple:

 
// Factorization the prime factor to obtain the maximum common divisor and the minimum common multiple int A [100]; int II, JJ; For (II = 0; II <100; II ++) {A [II] = 0;} II = 0; int I, n, m; CIN> N; CIN> m; cout <n <"= "; for (I = 2; I <= N & I <= m; I ++) {While (I <= N & I <= m) {If (M % I = 0 & N % I = 0) {cout <I <"*"; A [II] = I; II ++; N = N/I; M = m/I;} elsebreak ;}} cout <Endl; int comm_div = 1; for (JJ = 0; JJ <100; JJ ++) {if (a [JJ]! = 0) comm_div * = A [JJ]; elsebreak;} cout <"The common divisor is" <comm_div <Endl; cout <"The common multiple is" <comm_div * m * n <Endl;

Full count:

Int Div [1000]; for (INT I = 0; I <1000; I ++) Div [I] = 0; int sum, count; For (INT M = 1; M <= 1000; m ++) {COUNT = 0; sum = 0; For (INT n = 1; n <m; n ++) {If (M % N = 0) {Div [count] = N; count ++ ;}}for (INT p = 0; P <count; P ++) {sum + = div [p];} If (sum = m) {cout <m <Endl ;}}

Index Summary:

 
Const int A = 1; cout <& A <Endl; // A ++; // cout <& 1 <Endl; const char * A1 [] = {"123456", "1"}; const char * A2 [] = {"2", "2 "}; a1 [1] = "XXXX"; cout <A1 [0] <Endl; STD: cout <A1 [1] <STD: Endl; cout <A2 [0] <Endl; STD: cout <A2 [1] <STD: Endl;

 

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.