Ejemplo n.º 1
0
def readInt1D():
    """
    Read from sys.stdin and return an array of integers. An integer at
    the beginning of sys.stdin defines the array's length.
    """
    count = stdio.readInt()
    a = create1D(count, None)
    for i in range(count):
        a[i] = stdio.readInt()
    return a
Ejemplo n.º 2
0
def readInt1D():
    """
    Read from sys.stdin and return an array of integers. An integer at
    the beginning of sys.stdin defines the array's length.
    """
    count = stdio.readInt()
    a = create1D(count, None)
    for i in range(count):
        a[i] = stdio.readInt()
    return a
Ejemplo n.º 3
0
def main():
    w = stdio.readInt()
    h = stdio.readInt()
    tour = Tour()
    while not stdio.isEmpty():
        x = stdio.readFloat()
        y = stdio.readFloat()
        p = Point(x, y)
        tour.insertSmallest(p)
    tour.show()
    stdio.writef('Tour distance = %f\n', tour.distance())
    stdio.writef('Number of points = %d\n', tour.size())
Ejemplo n.º 4
0
def read():
    w = stdio.readInt()
    h = stdio.readInt()
    p = Picture(w, h)
    for col in range(w):
        for raw in range(h):
            r = stdio.readInt()
            g = stdio.readInt()
            b = stdio.readInt()
            c = Color(r, g, b)
            p.set(col, raw, c)
    return p
Ejemplo n.º 5
0
def main():
    w = stdio.readInt()
    h = stdio.readInt()
    stddraw.setCanvasSize(w, h)
    stddraw.setXscale(0, w)
    stddraw.setYscale(0, h)
    stddraw.setPenRadius(.005)
    while not stdio.isEmpty():
        x = stdio.readFloat()
        y = stdio.readFloat()
        p = Point(x, y)
        p.draw()
    stddraw.show()
Ejemplo n.º 6
0
def readBool2D():
    """
    Read from sys.stdin and return a two-dimensional array of booleans.
    Two integers at the beginning of sys.stdin define the array's
    dimensions.
    """
    rowCount = stdio.readInt()
    colCount = stdio.readInt()
    a = create2D(rowCount, colCount, False)
    for row in range(rowCount):
        for col in range(colCount):
            a[row][col] = stdio.readBool()
    return a
Ejemplo n.º 7
0
def readInt2D():
    """
    Read from sys.stdin and return a two-dimensional array of integers.
    Two integers at the beginning of sys.stdin define the array's
    dimensions.
    """
    rowCount = stdio.readInt()
    colCount = stdio.readInt()
    a = create2D(rowCount, colCount, 0)
    for row in range(rowCount):
        for col in range(colCount):
            a[row][col] = stdio.readInt()
    return a
Ejemplo n.º 8
0
def playTune2():
    notes = []
    #while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    hz = 440 * math.pow(2, pitch / 12.0)
    playNote(hz, 1)
Ejemplo n.º 9
0
def main():

    #button = Tkinter.Button(root, text='Play Tune', command=playTune2)

    #button.pack()

    #root.mainloop()

    #stdio.writeln('Playing')
    #playFile('woman.wav')

    stdio.writeln('Creating')
    sps = SAMPLE_RATE
    while not stdio.isEmpty():
        pitch = stdio.readInt()
        duration = stdio.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        notes = []
        for i in range(N + 1):
            notes.append(math.sin(2 * math.pi * i * hz / sps))
        stdio.writeln('Playing')
        playNotes(notes)

    root.mainloop()
Ejemplo n.º 10
0
def playTune2():
    notes = []
    #while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    hz = 440 * math.pow(2, pitch / 12.0)
    playNote(hz, 1)
Ejemplo n.º 11
0
def main():


    #button = Tkinter.Button(root, text='Play Tune', command=playTune2)

    #button.pack()


    #root.mainloop()



    #stdio.writeln('Playing')
    #playFile('woman.wav')

    stdio.writeln('Creating')
    sps = SAMPLE_RATE
    while not stdio.isEmpty():
        pitch = stdio.readInt()
        duration = stdio.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        notes = []
        for i in range(N+1):
            notes.append(math.sin(2*math.pi * i * hz / sps))
        stdio.writeln('Playing')
        playNotes(notes)

    root.mainloop()
Ejemplo n.º 12
0
def main():
    w = stdio.readInt()
    h = stdio.readInt()
    stddraw.setCanvasSize(w, h)
    stddraw.setXscale(0, w)
    stddraw.setYscale(0, h)
    stddraw.setPenRadius(.005)
    tour = Tour()
    while not stdio.isEmpty():
        x = stdio.readFloat()
        y = stdio.readFloat()
        p = Point(x, y)
        tour.insertSmallest(p)
    stdio.writef('Tour distance = %f\n', tour.distance())
    stdio.writef('Number of points = %d\n', tour.size())
    tour.draw()
    stddraw.show()
Ejemplo n.º 13
0
def playTune():
    sps = SAMPLE_RATE
    while not stdio.isEmpty():
        pitch = stdio.readInt()
        duration = stdio.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        notes = []
        for i in range(N + 1):
            notes.append(math.sin(2 * math.pi * i * hz / sps))
        #stdio.writeln('Playing')
        playNotes(notes)
Ejemplo n.º 14
0
def playTune():
    sps = SAMPLE_RATE
    while not stdio.isEmpty():
        pitch = stdio.readInt()
        duration = stdio.readFloat()
        hz = 440 * math.pow(2, pitch / 12.0)
        N = int(sps * duration)
        notes = []
        for i in range(N+1):
            notes.append(math.sin(2*math.pi * i * hz / sps))
        #stdio.writeln('Playing')
        playNotes(notes)
Ejemplo n.º 15
0
    def __init__(self):

        self._N = stdio.readInt()         # Number of bodies
        self._radius = stdio.readFloat()  # Radius of universe

        # the set scale for drawing on screen
        stddraw.setXscale(-self._radius, +self._radius)
        stddraw.setYscale(-self._radius, +self._radius)

        # read in the _N bodies
        self.orbs = []  # Array of bodies
        for i in range(self._N):
            rx   = stdio.readFloat()
            ry   = stdio.readFloat()
            vx   = stdio.readFloat()
            vy   = stdio.readFloat()
            mass = stdio.readFloat()
            position = [ rx, ry ]
            velocity = [ vx, vy ]
            r = vector.Vector(position)
            v = vector.Vector(velocity)
            self.orbs += [body.Body(r, v, mass)]
Ejemplo n.º 16
0
    def __init__(self):

        self._N = stdio.readInt()  # Number of bodies
        self._radius = stdio.readFloat()  # Radius of universe

        # the set scale for drawing on screen
        stddraw.setXscale(-self._radius, +self._radius)
        stddraw.setYscale(-self._radius, +self._radius)

        # read in the _N bodies
        self.orbs = []  # Array of bodies
        for i in range(self._N):
            rx = stdio.readFloat()
            ry = stdio.readFloat()
            vx = stdio.readFloat()
            vy = stdio.readFloat()
            mass = stdio.readFloat()
            position = [rx, ry]
            velocity = [vx, vy]
            r = vector.Vector(position)
            v = vector.Vector(velocity)
            self.orbs += [body.Body(r, v, mass)]
Ejemplo n.º 17
0
# randomsurfer.py
#-----------------------------------------------------------------------

import stdio
import stdarray
import sys
import random

# Accept an integer moves as a command-line argument. Read a
# transition matrix from standard input. Perform moves moves as
# prescribed by the transition matrix, and write to standard output
# the relative frequency of hitting each page.

moves = int(sys.argv[1])

n = stdio.readInt()
stdio.readInt()  # Discard the second int of standard input.

# Read the transition matrix from standard input.
# p[i][j] is the probability that the surfer moves from
# page i to page j.
p = stdarray.create2D(n, n, 0.0)
for i in range(n):
    for j in range(n):
        p[i][j] = stdio.readFloat()

# Perform the simulation, thus computing the hits array.
# hits[i] is the number of times the surfer hits page i.
hits = stdarray.create1D(n, 0)
step = stdarray.create1D(n, 0)
now = stdarray.create1D(n, 0)
"""Create a filter that reads in a sequence of integers and writes the integers,
removing repeated values that appear consecutively"""

import sys
import stdarray
import stdio
import random
import math

a = []
b = []
while not stdio.isEmpty():
    value = stdio.readInt()
    a += [value]
for i in range(len(a)):
    if a[i] != a[i-1]:
        b += [a[i]]
stdio.writeln(b)
Ejemplo n.º 19
0
import numpy as np
import picture as p

# newtons law of universal gravitation
# F = G*((m1*m2)/r**2))

# Kommandozeilenparameter
time = float(sys.argv[1])
delta_t = float(sys.argv[2])

g = 6.67e-11
bodies = []
current_time = 0

# Variablen vom Standardinput
num_bodies = stdio.readInt()
radius_univ = stdio.readFloat()

# Canvas vorbereiten
stddraw.setXscale(-radius_univ, radius_univ)
stddraw.setYscale(-radius_univ, radius_univ)
stddraw.setCanvasSize(1200, 1000)
stddraw.clear(stddraw.BLACK)


def force(mass_a, mass_b, position_a, position_b, g):
    delta = position_b - position_a
    # euklidische Distanz
    r = math.sqrt(delta[0]**2 + delta[1]**2)
    f = (g * mass_a * mass_b) / r**2
    force = f * (delta / r)
Ejemplo n.º 20
0
#   ----------------
#       1       30.1
#       2       17.6
#       3       12.5
#       4        9.7
#       5        7.9
#       6        6.7
#       7        5.8
#       8        5.1
#       9        4.6

counts = stdarray.create1D(10, 0)  # frequency of leading digit i
n = 0  # number of items read in

while not stdio.isEmpty():
    x = stdio.readInt()  # read in next integer
    digit = leadingDigit(x)  # compute leading digit
    counts[digit] += 1  # update frequency
    n += 1

# Write the frequency distribution.
for i in range(1, len(counts)):
    stdio.writef("%d: %6.1f%%\n", i, 100.0 * float(counts[i]) / float(n))

#-----------------------------------------------------------------------

# python benford.py < princeton-files.txt
# 1:   30.8%
# 2:   19.3%
# 3:   13.0%
# 4:    9.9%
Ejemplo n.º 21
0
import math
import stdio  # this is new!
import stdaudio

SPS = 44100
CONCERT_A = 440.0
NOTES_ON_SCALE = 12.0

while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    hz = CONCERT_A * (2.0**(pitch / NOTES_ON_SCALE))
    n = int(SPS * duration)
    note = [0.0] * (n + 1)
    for i in range(n + 1):
        note[i] = math.sin(2.0 * math.pi * i * hz / SPS)
    stdaudio.playSamples(note)

stdaudio.wait()
Ejemplo n.º 22
0
import stdio

stdio.write("Input a year: ")
year = stdio.readInt()

stdio.write("Input a month [1-12]: ")
month = stdio.readInt()

month_length = 30
if month in (1, 3, 5, 7, 8, 10, 12):
    month_length = 31
elif month == 2:
    if ((year % 4 == 0 and year != 100 == 0) or year % 400 == 0):
        month_length = 29
    else:
        month_length = 28
else:
    month_length = 30

stdio.write("Input a day [1-31]: ")
day = stdio.readInt()

if day < month_length:
    day += 1
else:
    day = 1
    if month == 12:
        month = 1
        year += 1
    else:
        month += 1
Ejemplo n.º 23
0
 def readSynapse(self, neuron):
     totalInputs = stdio.readInt('Total de entradas: ', 'x >= 1')
     neuron.synapse.setTotalInputs(totalInputs)
Ejemplo n.º 24
0
import stddraw
import stdio
import stdarray
from charge import Charge
from color import Color
from picture import Picture

# Read values from standard input to create an array of charged
# particles. Set each pixel color in an image to a grayscale value
# proportional to the total of the potentials due to the particles at
# corresponding points. Draw the resulting image to standard draw.

MAX_GRAY_SCALE = 255

# Read charges from standard input into an array.
n = stdio.readInt()
charges = stdarray.create1D(n)
for i in range(n):
    x0 = stdio.readFloat()
    y0 = stdio.readFloat()
    q0 = stdio.readFloat()
    charges[i] = Charge(x0, y0, q0)

# Create a Picture depicting potential values.
pic = Picture()
for col in range(pic.width()):
    for row in range(pic.height()):
        # Compute pixel color.
        x = 1.0 * col / pic.width()
        y = 1.0 * row / pic.height()
        v = 0.0
Ejemplo n.º 25
0
#-----------------------------------------------------------------------
# randomsurferhistogram.py
#-----------------------------------------------------------------------

import stdio
import stdarray
import stddraw
import sys
import random

t = int(sys.argv[1])   # number of moves
n = stdio.readInt()    # number of pages
stdio.readInt()        # ignore integer required by input format

# Read transition matrix.
# p[i][j] = prob. that surfer moves from page i to page j
p = stdarray.create2D(n, n, 0.0)
for i in range(n):
    for j in range(n):
        p[i][j] = stdio.readFloat()

# freq[i] = # times surfer hits page i
freq = stdarray.create1D(n, 0)

# Start at page 0.
page = 0
stddraw.createWindow()
stddraw.setXscale(-1, n)
stddraw.setYscale(0, t)
#stddraw.setPenRadius(.5/float(n))
stddraw.setPenRadius()
Ejemplo n.º 26
0
import stdio

stdio.writeln('nhap so = ')
so_input = stdio.readInt()

sodao = 0
tam = so_input

while tam > 0:

    sodao = sodao * 10 + tam % 10
    tam = tam // 10

if so_input == sodao:
    stdio.writeln('%d la do doi xung' % so_input)
else:
    stdio.writeln('%d khong phai la so doi xung' % so_input)
Ejemplo n.º 27
0
# randomsurfer.py
#-----------------------------------------------------------------------

import stdio
import stdarray
import sys
import random

# Accept an integer moves as a command-line argument. Read a
# transition matrix from standard input. Perform moves moves as
# prescribed by the transition matrix, and write to standard output
# the relative frequency of hitting each page.

moves = int(sys.argv[1])

n = stdio.readInt()
stdio.readInt() # Discard the second int of standard input.

# Read the transition matrix from standard input.
# p[i][j] is the probability that the surfer moves from
# page i to page j.
p = stdarray.create2D(n, n, 0.0)
for i in range(n):
    for j in range(n):
        p[i][j] = stdio.readFloat()

# Perform the simulation, thus computing the hits array.
# hits[i] is the number of times the surfer hits page i.
hits = stdarray.create1D(n, 0)
page = 0  # Start at page 0.
for i in range(moves):
Ejemplo n.º 28
0
import sys
import stdio

a = stdio.readInt()
b = stdio.readInt()
c = stdio.readString()
d = stdio.readInt()
e = stdio.readInt()

print(a,b,c,d,e)
Ejemplo n.º 29
0
#-----------------------------------------------------------------------
# maxmin.py
#-----------------------------------------------------------------------

import stdio

# Read integers from standard input until end-of-file. Then write
# the maxmimum an minimum of the integers to standard output.

maximum = stdio.readInt()
minimum = maximum

while not stdio.isEmpty():
    value = stdio.readInt()
    if value > maximum:
        maximum = value
    if value < minimum:
        minimum = value

stdio.writeln('maximum = ' + str(maximum) + \
              ', minimum = ' + str(minimum))

#-----------------------------------------------------------------------

# python maxmin.py
# 4 6 3 2 8 7 2 3 8 6 8 1
# maximum = 8, minimum = 1
Ejemplo n.º 30
0
import sys
import stdio

stdio.writeln('Nhap so can kiem tra: ')
n = int(stdio.readInt())

i = 2
if n < 2:
    stdio.writeln('%d khong phai la so nguyen to' % n)
elif n == 2:
    stdio.writeln('2 la so nguyen to')
else:
    for i in range(i, n):

        if n % i == 0:

            print('%d khong phai la so nguyen to' % n)
            break
    else:
        print('%d la so nguyen to' % n)
Ejemplo n.º 31
0
No_ = m * n
while True:
    no_run = 0
    stddraw.clear()
    if No_ > 0:
        for i in range(n):
            for j in range(m):
                if no_run < No_:
                    stddraw.setPenColor(stddraw.RED)
                    stddraw.filledCircle(i + .5, j + .5, .5)
                    no_run += 1
        stddraw.show(20)
        print(section)
        if section:
            stdio.write("Luot choi cua A[1-3]: ")
            k = stdio.readInt()
            No_ -= k
            section = False
        else:
            stdio.write("Luot choi cua B[1-3]: ")
            k = stdio.readInt()
            No_ -= k
            section = True
    else:
        if section:
            stdio.writeln("A Thang")
            break
        else:
            stdio.writeln("B Thang")
            break
stddraw.show()
Ejemplo n.º 32
0
#-----------------------------------------------------------------------
# transition.py
#-----------------------------------------------------------------------

import stdio
import stdarray

# Read links from standard input and write the corresponding
# transition matrix to standard output. First, process the input
# to count the outlinks from each page. Then apply the 90-10 rule to
# compute the transition matrix. Assume that there are no pages that
# have no outlinks in the input.

n = stdio.readInt()

counts = stdarray.create2D(n, n, 0)
outDegree = stdarray.create1D(n, 0)

while not stdio.isEmpty():
    # Accumulate link counts.
    i = stdio.readInt()
    j = stdio.readInt()
    outDegree[i] += 1
    counts[i][j] += 1

stdio.writeln(str(n) + ' ' + str(n))

for i in range(n):
    # Print probability distribution for row i.
    for j in range(n):
        # Print probability for column j.
Ejemplo n.º 33
0
import stdio

stdio.write('Mời bạn nhập điểm giữa kì: ')
Dgiuaki = stdio.readFloat()
stdio.write('Mới bạn nhập điểm cuối kỳ: ')
Dcuoiki = stdio.readFloat()
stdio.write('Mới bạn nhập số buổi vắng: ')
Solanvang = stdio.readInt()

Dcc = 10 - Solanvang
Dqt = Dcc * 0.3 + Dgiuaki * 0.7

if Solanvang > 3 or Dqt < 4:
    stdio.writeln('Cấm thi')
else:
    Dtb = Dqt * 0.3 + Dcuoiki * 0.7
    stdio.writeln('Điểm trung bình: %s' % Dtb)
    if Dtb >= 9:
        stdio.writeln('Xuất sắc')
    elif Dtb >= 8:
        stdio.writeln('Giỏi')
    elif Dtb >= 6.5:
        stdio.writeln('Khá')
    elif Dtb >= 4:
        stdio.writeln('Trung bình')
    elif Dtb < 4:
        stdio.writeln('Kém')
Ejemplo n.º 34
0
import stdio
import sys

# n=stdio.readInt()
dodainhiphan = stdio.readInt()

a = list(dodainhiphan * "0")
stdio.write(str(dodainhiphan * '0' + " "))
binary = ""
# while b <= dodainhiphan:
for k in range(1, (2**dodainhiphan)):
    check = 1
    for i in range(len(a) - 1, -1, -1):
        if (a[i] == "0"):
            a[i] = "1"
            check = 0
            break
        else:
            a[i] = '0'
    binary = ''.join(a)

    # if check == 1:
    # 	binary = "1".join(a)
    print(binary, end=" ")
stdio.writeln("")
Ejemplo n.º 35
0
# alignment.py: Reads from standard input, the output produced by
# edit_distance.py, i.e., input strings x and y, and the opt matrix. The
# program then recovers an optimal alignment from opt, and writes to
# standard output the edit distance between x and y and the alignment itself.

import stdarray
import stdio

# Read x, y, and opt from standard input.
x = stdio.readString()
y = stdio.readString()
stdio.readInt()
stdio.readInt()

# Compute M and N.
M = len(x)
N = len(y)
opt = stdarray.create2D(M + 1, N + 1, 0)
for i in range(M + 1):
    for j in range(N + 1):
        opt[i][j] = stdio.readInt()

# Write edit distance between x and y.
edit_distance = opt[0][0]
stdio.writef('Edit distance = %d\n', edit_distance)

# Recover and write an optimal alignment.
i = 0
j = 0
while i < M or j < N:
    if i == M or j == N:
Ejemplo n.º 36
0
    CONCERT_A_HZ = 440.0
    NOTES_ON_SCALE = 12.0
    hz = CONCERT_A_HZ * (2.0 ** (pitch / NOTES_ON_SCALE))
    a = tone(hz, t)
    hi = tone(2*hz, t)
    lo = tone(hz/2, t)
    h = superpose(hi, lo, .5, .5)
    return superpose(a, h, .5, .5)

#-----------------------------------------------------------------------

# Read sound samples from standard input, add harmonics, and play
# the resulting the sound to standard audio.

while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    a = note(pitch, duration)
    stdaudio.playArray(a)
stdaudio.wait()

#-----------------------------------------------------------------------

# python playthattunedeluxe.py < ascale.txt

# python playthattunedeluxe.py < elise.txt

# python playthattunedeluxe.py < entertainer.txt

# python playthattunedeluxe.py < firstcut.txt
Ejemplo n.º 37
0
 def __init__(self):
     self.lock = Lock()
     self.items = stdio.readInt('Total de neuronas: ', 'x >= 1')
     self.neurons = {}  #[Neuron(letter) for letter in uppercase]
     for letter in uppercase[:self.items]:
         self.neurons[letter] = Neuron(letter, self.lock)
Ejemplo n.º 38
0
#-----------------------------------------------------------------------
# transition.py
#-----------------------------------------------------------------------

import stdio
import stdarray

# Read links from standard input and write the corresponding
# transition matrix to standard output. First, process the input
# to count the outlinks from each page. Then apply the 90-10 rule to
# compute the transition matrix. Assume that there are no pages that
# have no outlinks in the input.

n = stdio.readInt()

linkCounts = stdarray.create2D(n, n, 0)
outDegrees = stdarray.create1D(n, 0)

while not stdio.isEmpty():
    # Accumulate link counts.
    i = stdio.readInt()
    j = stdio.readInt()
    if not linkCounts[i][j]:
        outDegrees[i] += 1
        linkCounts[i][j] += 1
print(linkCounts)

stdio.writeln(str(n) + ' ' + str(n))

for i in range(n):
    # Print probability distribution for row i.
Ejemplo n.º 39
0
#-----------------------------------------------------------------------
# rangefilter.py
#-----------------------------------------------------------------------

import stdio
import sys

# Accept integer command-line arguments lo and hi. Read integers from
# standard input until end-of-file. Write to standard output each of
# those integers that is in the range lo to hi, inclusive.

lo = int(sys.argv[1])
hi = int(sys.argv[2])
while not stdio.isEmpty():
    # Process one integer.
    value = stdio.readInt()
    if (value >= lo) and (value <= hi):
        stdio.write(str(value) + ' ')
stdio.writeln()

#-----------------------------------------------------------------------

# python rangefilter.py 100 400
# 358 1330 55 165 689 1014 3066 387 575 843 203 48 292 877 65 998
# 358 165 387 203 292

Ejemplo n.º 40
0
import sys
import stdio
'''stdio library couldn't be imported. 
it is added mauallu by saving into another folder.'''

n = int(sys.argv[1])

total = 0
for i in range(n):
    total += stdio.readInt()


print('Sum is %d' %total )

'''output:
%puthon addints.py 4
10
20
30
40
Sum is 100. '''


Ejemplo n.º 41
0
# Generate a random integer. Repeatedly read user guesses from
# standard input. Write 'Too low' or 'Too high' to standard output,
# as appropriate, in response to each guess. Write 'You win!' to
# standard output and exit when the user's guess is correct.

RANGE = 1000000

secret = random.randrange(1, RANGE+1)
stdio.write('I am thinking of a secret number between 1 and ')
stdio.writeln(RANGE)
guess = 0
while guess != secret:
    # Solicit one guess and provide one answer.
    stdio.write('What is your guess? ')
    guess = stdio.readInt()
    if (guess < secret):
        stdio.writeln('Too low')
    elif (guess > secret):
        stdio.writeln('Too high')
    else:
        stdio.writeln('You win!')
        
#-----------------------------------------------------------------------

# python twentyquestions.py
# I am thinking of a secret number between 1 and 1000000
# What is your guess? 500000
# Too low
# What is your guess? 750000     
# Too high
Ejemplo n.º 42
0
import stdio
N = stdio.readInt()
a = 0
if N >= 2:
    for i in range(2, N):
        if (N % i == 0):
            a = 1
    if a != 0:
        stdio.writeln('0')
    else:
        stdio.writeln('1')
# image showing the result of sampling the Mandelbrot set in that
# region at a 512*512 grid of equally spaced pixels. Color each pixel
# with a grayscale value that is determined by counting the number of
# iterations before the Mandelbrot sequence for the corresponding
# complex number grows past 2.0, up to 255.

MAX = 255

n = int(sys.argv[1])
xc = float(sys.argv[2])
yc = float(sys.argv[3])
size = float(sys.argv[4])

mColor = []
for i in range(256):
    r = stdio.readInt()
    g = stdio.readInt()
    b = stdio.readInt()
    mColor.append(Color(r, g, b))

pic = Picture(n, n)
for col in range(n):
    for row in range(n):
        x0 = xc - (size / 2) + (size * col / n)
        y0 = yc - (size / 2) + (size * row / n)
        z0 = complex(x0, y0)
        #gray = MAX - mandel(z0, MAX)
        color = mColor[mandel(z0, MAX)]
        pic.set(col, n - 1 - row, color)

stddraw.setCanvasSize(n, n)