Cách tìm thừa số của một số trong JavaScript

Một giải pháp Naive sẽ là lặp lại tất cả các số từ 1 đến n, kiểm tra xem số đó có chia hết n không và in nó. Dưới đây là một chương trình cho cùng

C++




// C++ implementation of Naive method to print all

// divisors

#include

using namespace std;

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
0

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
3

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
5
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
7

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

// C++ implementation of Naive method to print all0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 // C++ implementation of Naive method to print all2

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______10_______5// C++ implementation of Naive method to print all6// C++ implementation of Naive method to print all7

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6// C++ implementation of Naive method to print all9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______538_______1 // divisors2

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

// divisors5

C




// divisors6

// divisors

// divisors8

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 using0

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 using3

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4using5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8using7using8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

// C++ implementation of Naive method to print all0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 // C++ implementation of Naive method to print all2

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______540_______5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8// C++ implementation of Naive method to print all6namespace9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6// C++ implementation of Naive method to print all9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______538_______1 // divisors2

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

Java




std;6

// divisors

 

std;9  0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6 3

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______543_______5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8_______0_______3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
06
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
07
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
08

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
11
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
12
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
15
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6namespace9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
22

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______24  5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
27

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
31
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
32namespace9

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
36
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
37

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

Python3




The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
41

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
42

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
44

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
45
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
46

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______48
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
07

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______52
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
53
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
55

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
58_______0_______59
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
48
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
12
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
64

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
66
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
67_______0_______49
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
48_______0_______49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
48
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
75
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
07

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
77

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
78

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
66
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
32
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
36
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
87

C#




The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
88

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
89

using

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
91

 

std;9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
94

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
95

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6 3

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______543_______5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
0

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
3

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
15
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6namespace9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
22

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______24  5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
27

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
31
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
32
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
33

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
34
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
35namespace9

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
38

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
43

PHP




The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
44

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
45

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
46

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
0

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2_______10_______51
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
58
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
60
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
51// C++ implementation of Naive method to print all7
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
64

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
51
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
59
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
71

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
73
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
33
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6// C++ implementation of Naive method to print all7

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
80

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
73
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
82// C++ implementation of Naive method to print all7

// C++ implementation of Naive method to print all9

 

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
86

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
87

Javascript




The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
88

 

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
90

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
91

 

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
93

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
49
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
95

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
96

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______7
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
99

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 // C++ implementation of Naive method to print all02

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4// C++ implementation of Naive method to print all04
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6// C++ implementation of Naive method to print all06

// C++ implementation of Naive method to print all07

 

// C++ implementation of Naive method to print all0

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______537_______12// C++ implementation of Naive method to print all13
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
75// C++ implementation of Naive method to print all15// C++ implementation of Naive method to print all06

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6// C++ implementation of Naive method to print all9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
95

// C++ implementation of Naive method to print all20

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
95

// C++ implementation of Naive method to print all22

đầu ra

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100

Thời gian phức tạp. TRÊN)
Không gian phụ trợ. Ô(1)

Chúng ta có thể cải thiện giải pháp trên không?
Nếu chúng ta xem xét cẩn thận, tất cả các ước số đều có mặt theo cặp. Ví dụ: nếu n = 100, thì các cặp ước khác nhau là. (1,100), (2,50), (4,25), (5,20), (10,10)
Sử dụng thực tế này, chúng tôi có thể tăng tốc đáng kể chương trình của mình.  
Tuy nhiên, chúng ta phải cẩn thận nếu có hai ước bằng nhau như trong trường hợp (10, 10). Trong trường hợp như vậy, chúng tôi chỉ in một trong số chúng.  

Dưới đây là một triển khai cho cùng

C++




// C++ implementation of Naive method to print all23

#include

// C++ implementation of Naive method to print all25

using namespace std;

 

// C++ implementation of Naive method to print all30

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6// C++ implementation of Naive method to print all37

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 // C++ implementation of Naive method to print all42// C++ implementation of Naive method to print all43// C++ implementation of Naive method to print all44

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 // C++ implementation of Naive method to print all49

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4// C++ implementation of Naive method to print all53

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 // C++ implementation of Naive method to print all56

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
5
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
7

 

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4// C++ implementation of Naive method to print all63 // C++ implementation of Naive method to print all64

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
5
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6// C++ implementation of Naive method to print all68
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6 // C++ implementation of Naive method to print all70

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

// C++ implementation of Naive method to print all0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 // C++ implementation of Naive method to print all2

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______10_______5// C++ implementation of Naive method to print all6// C++ implementation of Naive method to print all7

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6// C++ implementation of Naive method to print all9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______538_______1 // divisors2

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

// divisors5

C




// C++ implementation of Naive method to print all23

// C++ implementation of Naive method to print all94

// C++ implementation of Naive method to print all25

 

// C++ implementation of Naive method to print all30

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6// C++ implementation of Naive method to print all37

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 // C++ implementation of Naive method to print all42// C++ implementation of Naive method to print all43// C++ implementation of Naive method to print all44

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 // C++ implementation of Naive method to print all49

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4// C++ implementation of Naive method to print all53

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 // C++ implementation of Naive method to print all56

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14using5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8using7// divisors28

 

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4// C++ implementation of Naive method to print all63 // C++ implementation of Naive method to print all64

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14using5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8// divisors36// divisors37

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

// C++ implementation of Naive method to print all0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 // C++ implementation of Naive method to print all2

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______540_______5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8// C++ implementation of Naive method to print all6namespace9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6// C++ implementation of Naive method to print all9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______538_______1 // divisors2

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

Java




// C++ implementation of Naive method to print all23

 

std;9  0

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6 3

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______543_______5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1____537_______37

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8_______0_______3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
06
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
07// divisors82

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
11
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
12
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14// C++ implementation of Naive method to print all53

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 // C++ implementation of Naive method to print all56

// divisors97____538_______98

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6#include 00

#include 01

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14// C++ implementation of Naive method to print all63 // C++ implementation of Naive method to print all64

// divisors97

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
15
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6 #include 08
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6 namespace9

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
22

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______24  5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
27

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
31
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
32namespace9

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
36
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
37

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

Python3




#include 38

#include 39 #include 40

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
44

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
45
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
46

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
95

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6#include 47

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______48
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
07

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______52
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
53
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49 #include 56

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
77

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
58_______0_______59
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
48
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
12
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
64

#include 67

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4#include 69

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
58_______539_______73
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
48
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49 #include 77

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
66
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
67
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4// C++ implementation of Naive method to print all63 #include 86

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14____539_______88

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
66 #include 91
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
58#include 73#include 95
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
49
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
48_______0_______49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
48
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
75
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
07

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
78

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
66
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
32
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
36
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
87

C#




using16

using17

using

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
91

 

std;9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
94

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
95

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6 3

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______543_______5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
4

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
77

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1using36

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1____540_______38

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
3 using43

using44____540_______45

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
3

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

using53

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14using55

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14using57

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2 using60

// divisors97____540_______62

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6namespace9

using53

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14// C++ implementation of Naive method to print all64

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14____537_______63

// divisors97____540_______62

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6

using73_______540_______74

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6namespace9

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
22

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______24  5
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
27

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
31using95

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
34
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
75using98namespace9

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1____537_______9

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
8

 

namespace06

PHP




The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
44

namespace08

namespace09

 

// C++ implementation of Naive method to print all30

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
49
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
2_______10_______51
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
95

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6namespace19

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6namespace21

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______7
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
58
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57 namespace28
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
51namespace9
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
64

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
6_______0_______5

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
51_______0_______59
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
71

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
1
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
5

#include 67

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4using55

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4using57

The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
4
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
2
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
8
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
51 #include 73
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57 namespace55
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
13

The divisors of 100 are: 
1 2 4 5 10 20 25 50 100
14
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
73
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
33
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
33
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
51#include 73
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
57
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
33
The divisors of 100 are: 
1 100 2 50 4 25 5 20 10
6// C++ implementation of Naive method to print all7

Làm cách nào để kiểm tra thừa số của một số trong JavaScript?

Ví dụ. Thừa số của số dương .
Vòng lặp for được sử dụng để lặp từ 1 đến số do người dùng nhập vào
Toán tử mô đun % được sử dụng để kiểm tra xem số có chia hết không
Trong mỗi lần lặp, một điều kiện được kiểm tra xem num có chia hết cho i không. .
Nếu điều kiện trên được đáp ứng, số sẽ được hiển thị

Làm cách nào để lấy thừa số nguyên tố của một số trong JavaScript?

function prime_factors(num) { function is_prime(num) { for (let i = 2; i <= Math. sqrt(số);