-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem-41.nb
116 lines (108 loc) · 3.82 KB
/
Problem-41.nb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(* Content-type: application/mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 7.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 145, 7]
NotebookDataLength[ 3726, 107]
NotebookOptionsPosition[ 3408, 91]
NotebookOutlinePosition[ 3746, 106]
CellTagsIndexPosition[ 3703, 103]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[CellGroupData[{
Cell[BoxData[{
RowBox[{
RowBox[{"ans", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]",
RowBox[{"For", "[",
RowBox[{
RowBox[{"i", " ", "=", " ", "9"}], " ", ",", " ",
RowBox[{"i", " ", "\[GreaterEqual]", " ", "4"}], " ", ",", " ",
RowBox[{"i", " ", "--"}], " ", ",", " ", "\[IndentingNewLine]",
"\[IndentingNewLine]",
RowBox[{
RowBox[{"f", " ", "=", " ",
RowBox[{"Table", "[", " ",
RowBox[{"x", " ", ",", " ",
RowBox[{"{",
RowBox[{"x", " ", ",", " ", "i"}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"p", " ", "=", " ",
RowBox[{"Permutations", "[", "f", "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"sz", " ", "=", " ",
RowBox[{"Length", "[", "p", "]"}]}], ";", "\[IndentingNewLine]",
"\[IndentingNewLine]",
RowBox[{"For", "[",
RowBox[{
RowBox[{"j", " ", "=", " ", "1"}], " ", ",", " ",
RowBox[{"j", " ", "\[LessEqual]", " ", "sz"}], " ", ",", " ",
RowBox[{"j", " ", "++"}], ",", "\[IndentingNewLine]",
RowBox[{
RowBox[{"d", " ", "=", " ",
RowBox[{"p", "[",
RowBox[{"[", "j", "]"}], "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"len", " ", "=", " ",
RowBox[{"Length", "[", " ", "d", "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"t", " ", "=", " ", "1"}], ";", "\[IndentingNewLine]",
RowBox[{"s", " ", "=", " ", "0"}], ";", "\[IndentingNewLine]",
RowBox[{"For", "[",
RowBox[{
RowBox[{"k", " ", "=", " ", "1"}], " ", ",", " ",
RowBox[{"k", " ", "\[LessEqual]", " ", "len"}], " ", ",", " ",
RowBox[{"k", " ", "++"}], ",",
RowBox[{
RowBox[{"s", " ", "+=", " ",
RowBox[{
RowBox[{"d", "[",
RowBox[{"[", "k", "]"}], "]"}], " ", "*", " ", "t"}]}], ";",
RowBox[{"t", " ", "*=", "10"}]}]}], "]"}], ";",
"\[IndentingNewLine]",
RowBox[{"If", " ", "[",
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"PrimeQ", "[", "s", "]"}], " ", "\[Equal]", " ", "True"}],
" ", ")"}], "&&", " ",
RowBox[{"s", " ", ">", " ", "ans"}]}], " ", ",", " ",
RowBox[{"ans", " ", "=", " ", "s"}]}], "]"}], ";"}]}], " ",
"\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"ans", " ", "\[NotEqual]", " ", "0"}], " ", ",", " ", "Break"}],
"]"}], ";"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"Print", "[", "ans", "]"}], ";"}]}], "Input",
CellChangeTimes->{{3.494424910791834*^9, 3.494425272050497*^9}, {
3.4944253341530495`*^9, 3.494425436011875*^9}}],
Cell[BoxData["7652413"], "Print",
CellChangeTimes->{3.495158668840292*^9}]
}, Open ]]
},
WindowSize->{607, 549},
WindowMargins->{{240, Automatic}, {47, Automatic}},
FrontEndVersion->"7.0 for Linux x86 (32-bit) (February 25, 2009)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[567, 22, 2747, 63, 407, "Input"],
Cell[3317, 87, 75, 1, 24, "Print"]
}, Open ]]
}
]
*)
(* End of internal cache information *)