Skip to content

Instantly share code, notes, and snippets.

@skibidi-ttd676767
Created December 28, 2025 02:09
Show Gist options
  • Select an option

  • Save skibidi-ttd676767/f8313aa4af459f2e331e27facdc34089 to your computer and use it in GitHub Desktop.

Select an option

Save skibidi-ttd676767/f8313aa4af459f2e331e27facdc34089 to your computer and use it in GitHub Desktop.
today
Display the source blob
Display the rendered blob
Raw
{
"cells" : [ {
"cell_type" : "code",
"id" : "initial_id",
"metadata" : {
"collapsed" : true,
"ExecuteTime" : {
"end_time" : "2025-12-28T01:25:36.920060Z",
"start_time" : "2025-12-28T01:24:33.988510Z"
}
},
"source" : [ "# Bài 1: Tính S(n) = 1 + 2 + 3 + … + n\n", "\"\"\"\n", "input: n int > 0\n", "output: sn\n", "\n", "sample\n", "n = 3\n", "s = 1 + 2 + 3 = 6\n", "\n", "n = 5\n", "s = 1 + 2 + 3 + 4 + 5 = 15\n", "\n", "b1: input n\n", "b2: s = 0\n", "b3: for i: 1 -> n:\n", " s = s + i\n", "b4: print s\n", "\n", "n = 4\n", "s = 0\n", "\n", "i = 1: s = s + i = 0 + 1 = 1\n", "i = 2: s = s + i = 1 + 2 = 3\n", "i = 3: s = s + i = 3 + 3 = 6\n", "i = 4: s = s + i = 6 + 4 = 10\n", "\n", "s = 10\n", "\"\"\"\n", "n = int(input())\n", "\n", "s = 0\n", "\n", "for i in range(1, n+1):\n", " s = s + i\n", "\n", "print(s)\n" ],
"outputs" : [ {
"name" : "stdout",
"output_type" : "stream",
"text" : [ "500000500000\n" ]
} ],
"execution_count" : 8
}, {
"metadata" : {
"ExecuteTime" : {
"end_time" : "2025-12-28T01:25:58.119372Z",
"start_time" : "2025-12-28T01:25:58.108871Z"
}
},
"cell_type" : "code",
"source" : "print(n*(n+1)//2)",
"id" : "f4a57fdeb144acec",
"outputs" : [ {
"name" : "stdout",
"output_type" : "stream",
"text" : [ "500000500000\n" ]
} ],
"execution_count" : 9
}, {
"metadata" : {
"ExecuteTime" : {
"end_time" : "2025-12-28T01:42:06.215693Z",
"start_time" : "2025-12-28T01:41:51.601719Z"
}
},
"cell_type" : "code",
"source" : [ "#Bài 2: Tính S(n) = 1^2 + 2^2 + … + n^2\n", "\"\"\"\n", "input: n int > 0\n", "output: sn\n", "\n", "sample:\n", "\n", "n = 3\n", "s = 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14\n", "\n", "n = 4\n", "s = 1^2 + 2^2 + 3^2 + 4^2 = 1 + 4 + 9 + 16 = 30\n", "\n", "b1: input n\n", "b2: s = 0\n", "b3: for i: 1 --> n\n", " s = s + i*i\n", "b4: print s\n", "\n", "n = 3\n", "s = 0\n", "i = 1: s = s + i*i = 0 + 1*1 = 0 + 1 = 1\n", "i = 2: s = s + i*i = 1 + 2*2 = 1 + 4 = 5\n", "i = 3: s = s + i*i = 5 + 3*3 = 5 + 9 = 14\n", "s = 14\n", "\"\"\"\n", "n = int(input())\n", "s = 0\n", "for i in range(1, n+1):\n", " s = s + i*i\n", "print(s)\n" ],
"id" : "899f8c2bdc443051",
"outputs" : [ {
"name" : "stdout",
"output_type" : "stream",
"text" : [ "333333833333500000\n" ]
} ],
"execution_count" : 11
}, {
"metadata" : {
"ExecuteTime" : {
"end_time" : "2025-12-28T01:45:41.401727Z",
"start_time" : "2025-12-28T01:45:41.391506Z"
}
},
"cell_type" : "code",
"source" : "n*(n + 1)*(2*n + 1)//6",
"id" : "57e8575193b309a8",
"outputs" : [ {
"data" : {
"text/plain" : [ "333333833333500000" ]
},
"execution_count" : 13,
"metadata" : { },
"output_type" : "execute_result"
} ],
"execution_count" : 13
}, {
"metadata" : {
"ExecuteTime" : {
"end_time" : "2025-12-28T02:02:33.479Z",
"start_time" : "2025-12-28T02:02:30.791638Z"
}
},
"cell_type" : "code",
"source" : [ "#Bài 3: Tính S(n) = 1 + ½ + 1/3 + … + 1/n\n", "\"\"\"\n", "input: n int > 0\n", "output: sn\n", "\n", "sample:\n", "n = 3\n", "sn = 1 + 1/2 + 1/3 = 1.8333333333333333\n", "n = 5\n", "sn = 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.283333333333333\n", "\n", "b1: input n\n", "b2: s = 0\n", "b3: for i: 1 -> n:\n", " s += 1/i\n", "b4: print(s)\n", "\n", "n = 3\n", "s = 0\n", "i = 1: s = s + 1/i = 0 + 1/1 = 0 + 1 = 1\n", "i = 2: s = s + 1/i = 1 + 1/2 = 1 + 0.5 = 1.5\n", "i = 3: s = s + 1/i = 1.5 + 1/3 = 1.5 + 0.333333333333333 = 1.8333333333333333\n", "print 1.833333333333333\n", "\n", "\n", "\"\"\"\n", "n = int(input())\n", "s = 0\n", "for i in range(1, n+1):\n", " s += 1/i\n", "print(s)" ],
"id" : "75c63fc99bbcac5f",
"outputs" : [ {
"name" : "stdout",
"output_type" : "stream",
"text" : [ "2.283333333333333\n" ]
} ],
"execution_count" : 15
}, {
"metadata" : { },
"cell_type" : "code",
"outputs" : [ ],
"execution_count" : null,
"source" : "",
"id" : "104d4cd27508a9e0"
} ],
"metadata" : {
"kernelspec" : {
"display_name" : "Python 3",
"language" : "python",
"name" : "python3"
},
"language_info" : {
"codemirror_mode" : {
"name" : "ipython",
"version" : 2
},
"file_extension" : ".py",
"mimetype" : "text/x-python",
"name" : "python",
"nbconvert_exporter" : "python",
"pygments_lexer" : "ipython2",
"version" : "2.7.6"
}
},
"nbformat" : 4,
"nbformat_minor" : 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment