티스토리 뷰
서로소 : 유클리드 알고리즘(http://uwangg.tistory.com/24)
문제 : http://koitp.org/problem/RELATIVLEY_PRIME/read/
1. 다틀림 ㅋㅋㅋㅋ 다시 풀어보자
소스코드
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
//class Solution {
class SW02_seoroso{
public static void main(String[] args)
throws FileNotFoundException
{
File file =new File("D:\\dev\\worksspace\\Solution\\src\\SW02_seoroso");
Scanner sc = new Scanner(file);
// Scanner sc = new Scanner(System.in);
// long start = System.currentTimeMillis();
while (sc.hasNext()) {
int N = sc.nextInt();
int[] nArr = new int[N];
for (int i = 0; i < N; i++) {
nArr[i] = sc.nextInt();
}
int[][] dp = new int[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i][j] = maxNanu(nArr[i],nArr[j]);
}
}
double answer = 0;
for (int i = 0; i < N-1; i++) {
for (int j = i+1; j < N; j++) {
if(dp[i][j] == 1){
answer += Math.pow(2, N-j-1);
}
}
}
System.out.println((int)(answer%10000003));
}
// long end = System.currentTimeMillis();
// System.out.println("time "+ (end-start)/1000.0);
}
private static int maxNanu(int i, int j) {
if(j == 0){
return i;
}else{
return maxNanu(j,i%j);
}
}
}
/*
3
2 3 4
3
*/
'Programming > Algorithm' 카테고리의 다른 글
[Algorithm] 백준 알고리즘 2983번 개구리 공주 (958) | 2016.11.07 |
---|---|
[Segment Tree] 백준 알고리즘 2042번 구간 합 (1329) | 2016.11.03 |
[중상] 집합 (1043) | 2016.10.31 |
[DP] 백준 알고리즘 1126번 같은 탑 (1322) | 2016.10.27 |
[DP] 백준 알고리즘 1514번 자물쇠 (252) | 2016.10.26 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 웰빙헬스
- Axis2
- 프리티어
- 부동산거래계약신고필증
- Bitnami
- 고운발크림
- 10cm
- AWS nodejs
- 로꼬
- Git
- AWS npm
- 생활코딩
- 중국어정리
- 중국어강의
- 중국어공부
- 뒤꿈치 건조함
- 수미네 반찬
- 알고리즘
- 자금조달계획서
- 마시내 탕수육
- 프렌즈
- 서머너즈워
- 크러쉬
- 노브랜드
- ES6
- s9+
- GraphQL
- 존맛탱
- 부동신 계약시 주의사항
- 혁오
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함