最小公倍數
時間限制:
1000?ms ?|? 內存限制:65535?KB 難度:
3 描述
為什么1小時有60分鐘,而不是100分鐘呢?這是歷史上的習慣導致。 但也并非純粹的偶然:60是個優秀的數字,它的因子比較多。 事實上,它是1至6的每個數字的倍數。即1,2,3,4,5,6都是可以除盡60。 我們希望尋找到能除盡1至n的的每個數字的最小整數m. 輸入
多組測試數據(少于500組)。
每行只有一個數n(1<=n<=100).輸出
輸出相應的m。樣例輸入
2
3
4
樣例輸出
2
6
12 1 //打表
2 import java.math.BigDecimal;
3 import java.math.BigInteger;
4 import java.util.Scanner;
5 public class Main{
6
7 public static void main(String args[]){
8 Scanner cin =
new Scanner(System.in);
9 /*final int MAX = 105;
10 int arr[] = new int[MAX];
11 BigInteger res[] = new BigInteger[MAX];
12 for(int i=1; i<MAX; ++i)arr[i] = i;
13 for(int i=2; i<MAX; ++i){
14 for(int j=i+1; j<MAX; ++j){
15 if(j%i == 0)
16 arr[j] /= arr[i];
17 }
18 }
19 for(int i=1; i<MAX; ++i)res[i] = BigInteger.ONE;
20 for(int i=2; i<MAX; ++i){
21 for(int j=2; j<i; ++j){
22 res[i] = res[i].multiply(BigInteger.valueOf(arr[j]));
23 }
24 }
25 for(int i=1; i<101; ++i){
26 int n = i;
27 System.out.println("\""+res[n+1] + "\",");
28 }*/
29 String s[] =
{
30 "1"
,
31 "2"
,
32 "6"
,
33 "12"
,
34 "60"
,
35 "60"
,
36 "420"
,
37 "840"
,
38 "2520"
,
39 "2520"
,
40 "27720"
,
41 "27720"
,
42 "360360"
,
43 "360360"
,
44 "360360"
,
45 "720720"
,
46 "12252240"
,
47 "12252240"
,
48 "232792560"
,
49 "232792560"
,
50 "232792560"
,
51 "232792560"
,
52 "5354228880"
,
53 "5354228880"
,
54 "26771144400"
,
55 "26771144400"
,
56 "80313433200"
,
57 "80313433200"
,
58 "2329089562800"
,
59 "2329089562800"
,
60 "72201776446800"
,
61 "144403552893600"
,
62 "144403552893600"
,
63 "144403552893600"
,
64 "144403552893600"
,
65 "144403552893600"
,
66 "5342931457063200"
,
67 "5342931457063200"
,
68 "5342931457063200"
,
69 "5342931457063200"
,
70 "219060189739591200"
,
71 "219060189739591200"
,
72 "9419588158802421600"
,
73 "9419588158802421600"
,
74 "9419588158802421600"
,
75 "9419588158802421600"
,
76 "442720643463713815200"
,
77 "442720643463713815200"
,
78 "3099044504245996706400"
,
79 "3099044504245996706400"
,
80 "3099044504245996706400"
,
81 "3099044504245996706400"
,
82 "164249358725037825439200"
,
83 "164249358725037825439200"
,
84 "164249358725037825439200"
,
85 "164249358725037825439200"
,
86 "164249358725037825439200"
,
87 "164249358725037825439200"
,
88 "9690712164777231700912800"
,
89 "9690712164777231700912800"
,
90 "591133442051411133755680800"
,
91 "591133442051411133755680800"
,
92 "591133442051411133755680800"
,
93 "1182266884102822267511361600"
,
94 "1182266884102822267511361600"
,
95 "1182266884102822267511361600"
,
96 "79211881234889091923261227200"
,
97 "79211881234889091923261227200"
,
98 "79211881234889091923261227200"
,
99 "79211881234889091923261227200"
,
100 "5624043567677125526551547131200"
,
101 "5624043567677125526551547131200"
,
102 "410555180440430163438262940577600"
,
103 "410555180440430163438262940577600"
,
104 "410555180440430163438262940577600"
,
105 "410555180440430163438262940577600"
,
106 "410555180440430163438262940577600"
,
107 "410555180440430163438262940577600"
,
108 "32433859254793982911622772305630400"
,
109 "32433859254793982911622772305630400"
,
110 "97301577764381948734868316916891200"
,
111 "97301577764381948734868316916891200"
,
112 "8076030954443701744994070304101969600"
,
113 "8076030954443701744994070304101969600"
,
114 "8076030954443701744994070304101969600"
,
115 "8076030954443701744994070304101969600"
,
116 "8076030954443701744994070304101969600"
,
117 "8076030954443701744994070304101969600"
,
118 "718766754945489455304472257065075294400"
,
119 "718766754945489455304472257065075294400"
,
120 "718766754945489455304472257065075294400"
,
121 "718766754945489455304472257065075294400"
,
122 "718766754945489455304472257065075294400"
,
123 "718766754945489455304472257065075294400"
,
124 "718766754945489455304472257065075294400"
,
125 "718766754945489455304472257065075294400"
,
126 "69720375229712477164533808935312303556800"
,
127 "69720375229712477164533808935312303556800"
,
128 "69720375229712477164533808935312303556800"
,
129 "69720375229712477164533808935312303556800"
,
130 };
131 while(cin.hasNext()){
132 int n =
cin.nextInt();
133 System.out.println(s[n-1
]);
134 }
135 }
136 }
?
轉載于:https://www.cnblogs.com/evidd/p/6775167.html
總結
以上是生活随笔為你收集整理的NYOJ--517--最小公倍数(大数打表)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。