https://www.acmicpc.net/problem/1978
# -*- encoding: cp949 -*- def prime_number(max_n): p = [0 for i in xrange(max_n+1)] for i in xrange(2,max_n+1): for j in xrange(i,max_n+1,i): if j!=i: p[j] = 1 prime = [i for i in xrange(2,max_n+1) if p[i]==0] return prime input() n = map(int,raw_input().split()) print len([i for i in n if i in set(prime_number(1000))])
https://www.acmicpc.net/problem/2960
# -*- encoding: cp949 -*- def prime_number(max_n, k): p = [0 for i in xrange(max_n+1)] c = 0 for i in xrange(2,max_n+1): for j in xrange(i,max_n+1,i): if p[j]==0: #print j p[j] = 1 c += 1 if c==k: return j n,k = map(int,raw_input().split()) print prime_number(n,k)
https://www.acmicpc.net/problem/4948
# -*- encoding: cp949 -*- def prime_number(max_n): p = [0 for i in xrange(max_n+1)] for i in xrange(2,max_n+1): for j in xrange(i,max_n+1,i): if j!=i: p[j] = 1 prime = [i for i in xrange(2,max_n+1) if p[i]==0] return prime p = prime_number(300000) while True: n = input() if n==0: break print len([i for i in p if n<i and i<=2*n])
https://www.acmicpc.net/problem/6588
# -*- encoding: cp949 -*- def prime_number(max_n): p = [0 for i in xrange(max_n+1)] for i in xrange(2,max_n+1): for j in xrange(i,max_n+1,i): if j!=i: p[j] = 1 prime = [i for i in xrange(2,max_n+1) if p[i]==0] return prime p = set(prime_number(1000000)) while True: n = input() if n==0:break flag = False for i in xrange(2,n/2+1): if i in p and n-i in p: print '{} = {} + {}'.format(n,i,n-i) flag = True break if not flag: print "Goldbach's conjecture is wrong."
https://www.acmicpc.net/problem/3896
# -*- encoding: cp949 -*- import bisect def prime_number(max_n): p = [0 for i in xrange(max_n+1)] for i in xrange(2,max_n+1): for j in xrange(i,max_n+1,i): if j!=i: p[j] = 1 prime = [i for i in xrange(2,max_n+1) if p[i]==0] return prime p = prime_number(1299750) s_p = set(p) for t in xrange(input()): n = input() if n in s_p: print 0 else: index = bisect.bisect(p,n) print p[index] - p[index-1]
https://www.acmicpc.net/problem/11502
# -*- encoding: cp949 -*- def prime_number(max_n): p = [0 for i in xrange(max_n+1)] for i in xrange(2,max_n+1): for j in xrange(i,max_n+1,i): if j!=i: p[j] = 1 prime = [i for i in xrange(2,max_n+1) if p[i]==0] return prime p = prime_number(1000) for t in xrange(input()): l=input() flag = False for i in p: if i<l/2+1: for j in p: if j<l/2+1: for k in p: if k<l/2+1: if i+j+k==l: print i,j,k flag = True break if flag: break if flag: break if not flag: 0
'algorithm > problem solving' 카테고리의 다른 글
acmicpc.net 1927,11279,11286(힙), 11055(LIS), 1956(플로이드) (0) | 2016.09.24 |
---|---|
acmicpc.net 1671(네트워크 플로우), 2606(플로이드) (0) | 2016.09.23 |
acmicpc.net 2252(위상 정렬), 1298(네트워크 플로우) (0) | 2016.09.21 |
acmicpc.net 1912(DP), 2293(DP), 2294(DP), 2156(DP) (0) | 2016.09.20 |
acmicpc.net 2352,1365,12015,12738,2631,11722,3745(LIS(DP)) (0) | 2016.09.19 |