Why does one hour have 60 minutes instead of 100 minutes? This is caused by historical habits. But it is not purely accidental: 60 is a good number, with many factors. In fact, it is a multiple of every number from 1 to 6. That is, can be divided into 60. We hope to find...
Why does one hour have 60 minutes instead of 100 minutes? This is caused by historical habits. But it is not purely accidental: 60 is a good number, with many factors.
In fact, it is a multiple of every number from 1 to 6. That is, can be divided into 60.
We want to find the minimum integer of each number that can divide by 1 to n.
Do not underestimate this number. it may be very large. for example, if n = 100, this number is:
69720375229712477164533808935312303556800
Write a program to obtain 1 ~ from the n (n <100) entered by the user ~ The minimum public multiple of n.
Example: User Input: 6 program output: 60
User input: 10 program output: 2520
If you want to use php to implement this method, you 'd better explain the idea first.
Reply content:
Why does one hour have 60 minutes instead of 100 minutes? This is caused by historical habits. But it is not purely accidental: 60 is a good number, with many factors.
In fact, it is a multiple of every number from 1 to 6. That is, can be divided into 60.
We want to find the minimum integer of each number that can divide by 1 to n.
Do not underestimate this number. it may be very large. for example, if n = 100, this number is:
69720375229712477164533808935312303556800
Write a program to obtain 1 ~ from the n (n <100) entered by the user ~ The minimum public multiple of n.
Example: User Input: 6 program output: 60
User input: 10 program output: 2520
If you want to use php to implement this method, you 'd better explain the idea first.
The general idea is to first calculate the least common multiple of two numbers (where the maximum common divisor of two numbers is obtained using the moving phase division, and then the least common multiple is obtained based on the formula), and then the next number is the least common multiple, until the last number ..
The code is as follows: (it is worth noting that the int type of php has exceeded the general overflow problem)
Function xmzenger ($ n) {// minimum common multiples of 1 and 2 $ res = 2; for ($ I = 1; $ I <= $ n; $ I ++) {// $ res is the minimum common approx. of the number before $ a, and $ B is given to continue and $ a to find the minimum common multiple $ a = $ I; $ B = $ res; // $ c is the product of two numbers $ c = $ a * $ B; // The exchange value makes $ a always greater than $ B if ($ a <$ B) {$ r = $ a; $ a = $ B; $ B = $ r;} // calculate the maximum common divisor of two natural numbers by division of the moving phase while (true) {$ r = $ a % $ B; // if $ r is 0, $ B is the maximum common approx. if ($ r = 0) {// formula used in primary school: "(a, B) [a, B] = AB (a, B are integers)" $ res = $ c/$ B; break ;} else {$ a = $ B; $ B = $ r ;}}return $ res;} echo xmzenger (10 );