# Tìm tất cả các ước của một số python

Viết chương trình Python để tìm tất cả các ước của một số nguyên hoặc số bằng vòng lặp for. Trong ví dụ Python này, vòng lặp for lặp từ 1 đến một số đã cho và kiểm tra xem mỗi số có chia hết cho số không. Nếu Đúng, in số đó dưới dạng ước số Show num = int(input("Please enter any integer to find divisors = ")) print("The Divisors of the Number = ") for i in range(1, num + 1): if num % i == 0: print(i) Chương trình Python tìm tất cả các ước của một số nguyên bằng vòng lặp while num = int(input("Please enter any integer to find divisors = ")) i = 1 while(i <= num): if num % i == 0: print(i) i = i + 1
Trong ví dụ Python này, chúng tôi đã tạo một hàm findDivisors sẽ tìm và trả về tất cả các ước của một số đã cho def findDivisors(num): for i in range(1, num + 1): if num % i == 0: print(i) # End of Function num = int(input("Please enter any integer to find divisors = ")) findDivisors(num) The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 n = 10 from 1 to 10 keep checking n % 1 == 0 print 1 n % 2 == 0 print 2 3, 4, 5, 6, 7, 8, 9 will not give remainder 0 exit loop; The 1 and 2 which gives remainder as 0 it also mean that n is perfectly divisible by 1 and 2 so in second for loop keep printing the quotient on dividing by 1 and 2 which left remainder 0 from 10 to 1 keep checking n % 1 == 0 print n/1 n % 2 == 0 print n/2 exit loop4 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 n = 10 from 1 to 10 keep checking n % 1 == 0 print 1 n % 2 == 0 print 2 3, 4, 5, 6, 7, 8, 9 will not give remainder 0 exit loop; The 1 and 2 which gives remainder as 0 it also mean that n is perfectly divisible by 1 and 2 so in second for loop keep printing the quotient on dividing by 1 and 2 which left remainder 0 from 10 to 1 keep checking n % 1 == 0 print n/1 n % 2 == 0 print n/2 exit loop6 n = 10 from 1 to 10 keep checking n % 1 == 0 print 1 n % 2 == 0 print 2 3, 4, 5, 6, 7, 8, 9 will not give remainder 0 exit loop; The 1 and 2 which gives remainder as 0 it also mean that n is perfectly divisible by 1 and 2 so in second for loop keep printing the quotient on dividing by 1 and 2 which left remainder 0 from 10 to 1 keep checking n % 1 == 0 print n/1 n % 2 == 0 print n/2 exit loop7_______6_______8 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001
The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______0 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 1008 `// A O(sqrt(n)) program that prints all divisors` 0`// A O(sqrt(n)) program that prints all divisors` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______660_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 1008 `// A O(sqrt(n)) program that prints all divisors` 0`// A O(sqrt(n)) program that prints all divisors` 1
The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// in sorted order` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// in sorted order` 3The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______665_______5 `// in sorted order` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______670_______1 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 `#include ` 6The divisors of 100 are: 1 2 4 5 10 20 25 50 1008 `// A O(sqrt(n)) program that prints all divisors` 0`using` 1
The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 `using` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______8 `namespace` 0`namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______5 `namespace` 6
## Java
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______685_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______685_______7 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1004 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 10007_______5_______08 The divisors of 100 are: 1 2 4 5 10 20 25 50 10009 The divisors of 100 are: 1 2 4 5 10 20 25 50 10014 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015_______5_______16 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______0 The divisors of 100 are: 1 2 4 5 10 20 25 50 10019_______5_______20 The divisors of 100 are: 1 2 4 5 10 20 25 50 10021
The divisors of 100 are: 1 2 4 5 10 20 25 50 1007_______5_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006 The divisors of 100 are: 1 2 4 5 10 20 25 50 10027 The divisors of 100 are: 1 2 4 5 10 20 25 50 10028 `// A O(sqrt(n)) program that prints all divisors` 0`// A O(sqrt(n)) program that prints all divisors` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 10027 The divisors of 100 are: 1 2 4 5 10 20 25 50 10028 `// A O(sqrt(n)) program that prints all divisors` 0`// A O(sqrt(n)) program that prints all divisors` 1
The divisors of 100 are: 1 2 4 5 10 20 25 50 10027 `// in sorted order` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 10027 The divisors of 100 are: 1 2 4 5 10 20 25 50 10041 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// in sorted order` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______665_______5 `// in sorted order` 5
`#include ` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 10054 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015 The divisors of 100 are: 1 2 4 5 10 20 25 50 10056 The divisors of 100 are: 1 2 4 5 10 20 25 50 10020 The divisors of 100 are: 1 2 4 5 10 20 25 50 10058 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______28 `// A O(sqrt(n)) program that prints all divisors` 0The divisors of 100 are: 1 2 4 5 10 20 25 50 10062 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______66 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______68 `std;` 7 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 10071 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 10075 The divisors of 100 are: 1 2 4 5 10 20 25 50 10076 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1002 The divisors of 100 are: 1 2 4 5 10 20 25 50 10080 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
## Python3The divisors of 100 are: 1 2 4 5 10 20 25 50 10085 The divisors of 100 are: 1 2 4 5 10 20 25 50 10086
The divisors of 100 are: 1 2 4 5 10 20 25 50 10088
The divisors of 100 are: 1 2 4 5 10 20 25 50 10089
The divisors of 100 are: 1 2 4 5 10 20 25 50 10090 The divisors of 100 are: 1 2 4 5 10 20 25 50 10091 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______93 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10095
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______97 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015
The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10020
The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______6_______21 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______0 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______660_______3_______6_______38 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 10093 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______55 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 10093 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094
The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______80
## C#
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______685_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______685_______7 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1004 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003_______5_______02_______5_______08 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003_______5_______05 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 The divisors of 100 are: 1 2 4 5 10 20 25 50 10008 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 The divisors of 100 are: 1 2 4 5 10 20 25 50 10013 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______0 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001
The divisors of 100 are: 1 2 4 5 10 20 25 50 1007_______5_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006 The divisors of 100 are: 1 2 4 5 10 20 25 50 10027 The divisors of 100 are: 1 2 4 5 10 20 25 50 10023 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 10027 The divisors of 100 are: 1 2 4 5 10 20 25 50 10023 `namespace` 1
The divisors of 100 are: 1 2 4 5 10 20 25 50 10027_______5_______34 The divisors of 100 are: 1 2 4 5 10 20 25 50 10027 The divisors of 100 are: 1 2 4 5 10 20 25 50 10036 The divisors of 100 are: 1 2 4 5 10 20 25 50 10027_______5_______38 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// in sorted order` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______665_______5 `// in sorted order` 5
The divisors of 100 are: 1 2 4 5 10 20 25 50 10046 The divisors of 100 are: 1 2 4 5 10 20 25 50 10048 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 The divisors of 100 are: 1 2 4 5 10 20 25 50 10053 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______55 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______61 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______68 `std;` 7 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 10066 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 10070 `namespace` 0`namespace` 1`namespace` 3The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 10078 The divisors of 100 are: 1 2 4 5 10 20 25 50 10079 ## PHPThe divisors of 100 are: 1 2 4 5 10 20 25 50 10080 The divisors of 100 are: 1 2 4 5 10 20 25 50 10081 The divisors of 100 are: 1 2 4 5 10 20 25 50 10082 The divisors of 100 are: 1 2 4 5 10 20 25 50 10083
The divisors of 100 are: 1 2 4 5 10 20 25 50 10084 The divisors of 100 are: 1 2 4 5 10 20 25 50 10085 The divisors of 100 are: 1 2 4 5 10 20 25 50 10086 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______88 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______97 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______99 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______96 The divisors of 100 are: 1 2 4 5 10 20 25 50 10097 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______99 `// A O(sqrt(n)) program that prints all divisors` 00The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `// A O(sqrt(n)) program that prints all divisors` 04 `// A O(sqrt(n)) program that prints all divisors` 05
The divisors of 100 are: 1 2 4 5 10 20 25 50 10088 `namespace` 1`// A O(sqrt(n)) program that prints all divisors` 04`// A O(sqrt(n)) program that prints all divisors` 12The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// A O(sqrt(n)) program that prints all divisors` 04 `// A O(sqrt(n)) program that prints all divisors` 21The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______0 `// A O(sqrt(n)) program that prints all divisors` 28_______5_______88 `// A O(sqrt(n)) program that prints all divisors` 04 `// A O(sqrt(n)) program that prints all divisors` 32`// A O(sqrt(n)) program that prints all divisors` 04The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 36 `// A O(sqrt(n)) program that prints all divisors` 04 `// A O(sqrt(n)) program that prints all divisors` 38The divisors of 100 are: 1 2 4 5 10 20 25 50 10097 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______660_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 36 `// A O(sqrt(n)) program that prints all divisors` 04 `// A O(sqrt(n)) program that prints all divisors` 38The divisors of 100 are: 1 2 4 5 10 20 25 50 10097
The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 52The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 54The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 The divisors of 100 are: 1 2 4 5 10 20 25 50 10096 `// A O(sqrt(n)) program that prints all divisors` 57The divisors of 100 are: 1 2 4 5 10 20 25 50 10099 `// A O(sqrt(n)) program that prints all divisors` 59The divisors of 100 are: 1 2 4 5 10 20 25 50 10088 `// A O(sqrt(n)) program that prints all divisors` 04The divisors of 100 are: 1 2 4 5 10 20 25 50 10097 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______665_______5 `// in sorted order` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______46 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______48 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `// A O(sqrt(n)) program that prints all divisors` 04 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 `// A O(sqrt(n)) program that prints all divisors` 79The divisors of 100 are: 1 2 4 5 10 20 25 50 10096 `// A O(sqrt(n)) program that prints all divisors` 82
`// A O(sqrt(n)) program that prints all divisors` 36 The divisors of 100 are: 1 2 4 5 10 20 25 50 10096 `// A O(sqrt(n)) program that prints all divisors` 57`// A O(sqrt(n)) program that prints all divisors` 04`// A O(sqrt(n)) program that prints all divisors` 93
The divisors of 100 are: 1 2 4 5 10 20 25 50 10097
## Javascript
The divisors of 100 are: 1 2 4 5 10 20 25 50 10081 The divisors of 100 are: 1 2 4 5 10 20 25 50 10082 The divisors of 100 are: 1 2 4 5 10 20 25 50 10083
The divisors of 100 are: 1 2 4 5 10 20 25 50 10084 The divisors of 100 are: 1 2 4 5 10 20 25 50 10085 The divisors of 100 are: 1 2 4 5 10 20 25 50 10086 `// in sorted order` 11The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______97 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______99 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______18 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______20 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `// in sorted order` 23
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______0 `// in sorted order` 37The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// in sorted order` 39`namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______660_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// in sorted order` 39`namespace` 1
The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 52The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// A O(sqrt(n)) program that prints all divisors` 54The divisors of 100 are: 1 2 4 5 10 20 25 50 1007 `// in sorted order` 55The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______665_______5 `// in sorted order` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______46 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______48 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `// in sorted order` 68
`namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
Đầu ra The divisors of 100 are: 1 2 4 5 10 20 25 50 100 Thời gian phức tạp. O(sqrt(n)) Phương pháp 2 Tiếp cận. Trong cách tiếp cận bên dưới bằng cách sử dụng vòng lặp for, trước tiên chúng ta chỉ in các số có phần dư là 0 và một khi chúng ta phá vỡ vòng lặp, chúng ta chỉ in thương của các số có phần còn lại là 0 Hãy hiểu thông qua một ví dụ. ## C++
The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 The divisors of 100 are: 1 2 4 5 10 20 25 50 1004 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______3 `#include ` 00The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `#include ` 03The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______670_______08 The divisors of 100 are: 1 2 4 5 10 20 25 50 10097 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______0 `#include ` 15`#include ` 17The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `#include ` 22The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______670_______27 The divisors of 100 are: 1 2 4 5 10 20 25 50 10097 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 `using` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______670_______38 `namespace` 0The divisors of 100 are: 1 2 4 5 10 20 25 50 10097
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______3
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______5 `namespace` 6
## C
The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 The divisors of 100 are: 1 2 4 5 10 20 25 50 1004 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005_______5_______3 `#include ` 00The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `#include ` 62The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______8 `// A O(sqrt(n)) program that prints all divisors` 0_______660_______1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `#include ` 22The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______8 `// A O(sqrt(n)) program that prints all divisors` 0_______670_______92The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 `using` 5The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______8 `namespace` 0`namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______5 `namespace` 6
## Java
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006
The divisors of 100 are: 1 2 4 5 10 20 25 50 10068 `std;` 7 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 The divisors of 100 are: 1 2 4 5 10 20 25 50 1004 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005_______5_______3 `#include ` 00The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3_______673_______30 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015 `using` 32The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 10019_______5_______20_______6_______35 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______673_______41____6_______34 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______0 `using` 48The divisors of 100 are: 1 2 4 5 10 20 25 50 10015 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3_______673_______59 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015_______5_______58 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 10019_______5_______20_______6_______35 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______673_______70 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 10068 `std;` 7 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 `using` 80The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______75 The divisors of 100 are: 1 2 4 5 10 20 25 50 10076 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______2 The divisors of 100 are: 1 2 4 5 10 20 25 50 10080 `namespace` 1
## Python3
The divisors of 100 are: 1 2 4 5 10 20 25 50 10088 `std;` 0 `using` 99
The divisors of 100 are: 1 2 4 5 10 20 25 50 10090 `namespace` 02
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______00_______5_______94 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______08 `namespace` 09`using` 99 `namespace` 11The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10020 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______6_______31
The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10015
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 `namespace` 39_______5_______20The divisors of 100 are: 1 2 4 5 10 20 25 50 10015 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10094 The divisors of 100 are: 1 2 4 5 10 20 25 50 10020 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______6_______31 `namespace` 59The divisors of 100 are: 1 2 4 5 10 20 25 50 10094
The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______80
## C#
The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 The divisors of 100 are: 1 2 4 5 10 20 25 50 1002 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 The divisors of 100 are: 1 2 4 5 10 20 25 50 1004 The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3_______6_______4 The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 `namespace` 93The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______5_______23 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `std;` 09The divisors of 100 are: 1 2 4 5 10 20 25 50 1003 `std;` 11The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______685_______18 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 10068 `std;` 7 The divisors of 100 are: 1 2 4 5 10 20 25 50 1001 `std;` 29`std;` 30 `std;` 31The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______5_______70 `namespace` 0`namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______3
## Javascript
The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 The divisors of 100 are: 1 2 4 5 10 20 25 50 10086 `// in sorted order` 11The divisors of 100 are: 1 2 4 5 10 20 25 50 1005 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `std;` 53 `std;` 54The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______665_______39 `namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______6_______3 `std;` 53 `std;` 68The divisors of 100 are: 1 2 4 5 10 20 25 50 1000 `// in sorted order` 30The divisors of 100 are: 1 2 4 5 10 20 25 50 1002_______665_______79 `std;` 75The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______5
The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______665_______79 `namespace` 0`namespace` 1The divisors of 100 are: 1 2 4 5 10 20 25 50 1006_______677_______3 The divisors of 100 are: 1 2 4 5 10 20 25 50 1006
Đầu ra The divisors of 100 are: 1 2 4 5 10 20 25 50 100 Độ phức tạp về thời gian. O(sqrt(n)) Không gian phụ trợ. Ô(1) Điều kiện if giữa hai vòng lặp được sử dụng khi các thừa số góc trong điều kiện của vòng lặp có chênh lệch bằng 1 (ví dụ: thừa số 30 (5,6) ở đây, 5 sẽ được in hai lần; để giải quyết vấn đề đó, bước này là bắt buộc Bài viết này được đóng góp bởi Ashutosh Kumar. Vui lòng viết nhận xét nếu bạn thấy bất cứ điều gì không chính xác hoặc nếu bạn muốn chia sẻ thêm thông tin về chủ đề đã thảo luận ở trên |