본문 바로가기

분류 전체보기1523

[백준] 2061 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import sys import math def checkPrime(n): sieve=[True]*n a=int(math.sqrt(n)) for i in range(2,a+1): if sieve[i]: for j in range(i+i,n,i): sieve[j]=False return [i for i in range(2,n) if sieve[i]==True] p,k=map(int, sys.stdin.readline().split()) ans=0 tmp=checkPrime(k) for i in range (len(tmp)): if p%tmp[i]==0: print("BAD %d"%tmp[i]) exit() if ans==.. 2020. 12. 18.
[백준] 2010 1 2 3 4 5 6 7 import sys n = int(sys.stdin.readline()) ans=0 for i in range(n): tmp=int(sys.stdin.readline()) ans+=tmp print(ans- (n-1)) cs 2020. 12. 18.
[백준] 1975 1 2 3 4 5 6 7 8 9 10 11 12 13 import sys t = int(sys.stdin.readline()) for i in range(t): n = int(sys.stdin.readline()) cnt = 0 for j in range(2, n+1): tmp = n while (tmp//j)!=0: if tmp%j==0: cnt+=1 tmp/=j else: break print(cnt) cs python3로 채점하면 시간초과나서 pypy3로 통과됐습니다. 죄송합니다 이런 식으로 짜면되는데 그대로 참조하시면 안됩니더 2020. 12. 17.
[백준] 1964 1 2 3 4 5 6 import sys n=int(sys.stdin.readline()) tmp=[5] for i in range(1,n): tmp.append(3*(i+1)+1) print( sum(tmp)%45678) cs 저는 알고리즘 분류- 수학 으로 돼있으면 주로 점화식을 구해서 구현하는 방식입니다. 그래서 항상 펜과 노트를 책상앞에 두고 풉니다. 2020. 12. 17.
[백준] 1864 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import sys while 1: s=sys.stdin.readline() ans = 0 if s[0]=="#": exit() else: for i in range(len(s)-1): if s[i] == '-': tmp = 0 elif s[i] == "\\": tmp = 1 elif s[i] == '(': tmp = 2 elif s[i] == '@': tmp = 3 elif s[i] == '?': tmp = 4 elif s[i] == '>': tmp = 5 elif s[i] == '&': tmp = 6 elif s[i] == '%': tmp = 7 elif s[i] == '/': tmp = -1 ans+=tmp*pow.. 2020. 12. 17.
[백준] 1837 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import sys import math def checkPrime(n): sieve=[True]*n a=int(math.sqrt(n)) for i in range(2,a+1): if sieve[i]: for j in range(i+i,n,i): sieve[j]=False return [i for i in range(2,n) if sieve[i]==True] p,k=map(int, sys.stdin.readline().split()) ans=0 tmp=checkPrime(k) for i in range (len(tmp)): if p%tmp[i]==0: print("BAD %d"%tmp[i]) exit() if ans==.. 2020. 12. 17.
[백준] 1703 1 2 3 4 5 6 7 8 9 10 11 import sys while 1: tmp=list(map(int, sys.stdin.readline().split())) if tmp[0]==0: exit() else: ans=1 if tmp[0]==1: print(tmp[1]-tmp[2]) else: for i in range(1,tmp[0]+1): ans=tmp[i*2-1]*ans-tmp[i*2] print(ans) cs 2020. 12. 17.
[백준] 1598 1 2 3 4 5 import sys a,b=map(int,sys.stdin.readline().split()) a-=1 b-=1 print( abs (a//4-b//4)+abs(b%4-a%4)) cs python은 근본있는 언어라 0부터 시작하기에 a,b를 각각 1을 빼줍니다. 4를 기준으로 하는 수열이라 보시면 쉽게 풀 수 있습니다. 2020. 12. 17.
[백준] 1267 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import sys n=int(sys.stdin.readline()) tmp=list (map(int, sys.stdin.readline().split())) youn=0 mins=0 for i in range(n): if tmp[i] 2020. 12. 17.
[백준] 1247 1 2 3 4 5 6 7 8 9 10 import sys tmp=[] for i in range(3): for j in range(int(sys.stdin.readline())): tmp.append( int(sys.stdin.readline())) if sum(tmp)>0: print("+") if sum(tmp) == 0: print("0") if sum(tmp) 2020. 12. 17.
[백준] 1085 1 2 3 4 5 a,b,c,d=map(int, input().split()) if a==c or b== d: print(0) else: print (min(abs(a-c),abs(d-b),a,b)) cs 2020. 12. 17.
[백준] 19944 1 2 3 4 5 n,m=map(int,input().split()) if m==1 or m==2: print("NEWBIE!") elif n 2020. 12. 17.