Skip to content

Instantly share code, notes, and snippets.

@regonn
Created December 22, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regonn/b4bd9179b946dc6cdca7ddc902bc5bdc to your computer and use it in GitHub Desktop.
Save regonn/b4bd9179b946dc6cdca7ddc902bc5bdc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin> 243241\n"
]
},
{
"data": {
"text/plain": [
"\"243241\""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N = String(readline(STDIN))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"is_two (generic function with 1 method)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is_two(x) = x == \"2\" "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6-element Array{SubString{String},1}:\n",
" \"2\"\n",
" \"4\"\n",
" \"3\"\n",
" \"2\"\n",
" \"4\"\n",
" \"1\""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length(filter(x -> is_two(x),split(N,\"\")))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"B"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin> 3 5 2\n"
]
},
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 3\n",
" 5\n",
" 2"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N, H, W = map(x -> parse(Int64,x), split(readline(STDIN)))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin> 10 3\n",
"stdin> 5 2\n",
"stdin> 2 5\n"
]
},
{
"data": {
"text/plain": [
"3-element Array{Array{Int64,1},1}:\n",
" [10, 3]\n",
" [5, 2] \n",
" [2, 5] "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = [map(x -> parse(Int64,x), split(readline(STDIN))) for _ in 1:N]"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"cuttable (generic function with 1 method)"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function cuttable(h, w, board) \n",
" return board[1] >= h && board[2] >= w\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length(filter(board -> cuttable(H, W, board), data))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"C"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin> 10000000000 10000000000\n"
]
},
{
"data": {
"text/plain": [
"2-element Array{Int128,1}:\n",
" 10000000000\n",
" 10000000000"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N, P = map(x -> parse(Int128,x), split(readline(STDIN)))"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2^N"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"大きな数で計算しようとすると0になってしまう、BigIntの扱いも分からず終了"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"cal (generic function with 1 method)"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function cal(N::Int128, P::Int128)\n",
" i::UInt128 = 1\n",
" answer::UInt128 = 1\n",
" in::UInt128 = 1\n",
" if N == 1\n",
" return P\n",
" end\n",
" if P == 1\n",
" return 1\n",
" end\n",
" \n",
" while in < P\n",
" if P % in == 0\n",
" answer = i\n",
" end\n",
" i = i + 1\n",
" println(i^N)\n",
" in = i^N\n",
" println(in)\n",
" end\n",
" return answer\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"ename": "LoadError",
"evalue": "\u001b[91mDivideError: integer division error\u001b[39m",
"output_type": "error",
"traceback": [
"\u001b[91mDivideError: integer division error\u001b[39m",
"",
"Stacktrace:",
" [1] \u001b[1mcal\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::UInt128, ::UInt128\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./In[24]:13\u001b[22m\u001b[22m"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"0\n"
]
}
],
"source": [
"cal(N, P)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"D"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin> 3\n"
]
},
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N = parse(Int64, readline(STDIN))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin> 100000\n",
"stdin> 30000\n",
"stdin> 20000\n"
]
},
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 100000\n",
" 30000\n",
" 20000"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = [parse(Int64,readline(STDIN)) for _ in 1:N]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"second\n"
]
}
],
"source": [
"println(length(filter(isodd, data)) > 0 ? \"first\" : \"second\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.6.2",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment