--- tags: DICE C --- 17-5 公倍數 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- 題目 -- ```! 請撰寫一程式,輸入三個整數(小於1000),找出小於等於1000的所有公倍數。 輸入範例: 30 45 18 輸出範例: 90 180 270 360 450 540 630 720 810 900 990 ``` 程式碼 -- ```c= #include <stdio.h> int main() { int a, b, c, ans = 1; scanf("%d %d %d", &a, &b, &c); if (a == 1 || b == 1 || c == 1) { if (a * b * c <= 1000) { ans = a * b * c; printf("%d ", ans); for (int i = 2; ans * i <= 1000; i++) { printf("%d ", ans * i); } } } else if (a >= 2 && b >= 2 && c >= 2) { //質因數分解 for (int i = 2; a >= i && b >= i && c >= i; i++) { while (a % i == 0 && b % i == 0 && c % i == 0) { a /= i; b /= i; c /= i; ans *= i; } } //進一步做質因數分解 for (int i = 2; a >= i || b >= i || c >= i; i++) { while (a % i == 0 && b % i == 0) { a /= i; b /= i; ans *= i; } while (a % i == 0 && c % i == 0) { a /= i; c /= i; ans *= i; } while (b % i == 0 && c % i == 0) { b /= i; c /= i; ans *= i; } } if (ans * a * b * c <= 1000) { ans = ans * a * b * c; printf("%d ",ans); for (int i = 2; ans * i <= 1000; i++) { printf("%d ", ans * i); } } } return 0; } ``` 輸入 -- ```! 30 45 18 ``` 輸出 -- ```! 90 180 270 360 450 540 630 720 810 900 990 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-17-5" width="100%"></iframe> --- {%hackmd i1nMRrZcTFmTvoF897K9zg %}