Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOJ_2725_보이는 점의 개수 #46

Open
changicho opened this issue Jan 10, 2020 · 0 comments
Open

BOJ_2725_보이는 점의 개수 #46

changicho opened this issue Jan 10, 2020 · 0 comments
Labels
not clear 진행중인 코드
Milestone

Comments

@changicho
Copy link
Owner

2725. 보이는 점의 개수

링크

난이도 정답률(_%)
Silver III 51

설계

정리

내 코드 빠른 코드

고생한 점

코드

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool map[1002][1002] = { false, };

int gcd(int a, int b) {
	if (b > a) swap(a, b);
	int new_a = a, new_b = b;

	while (b != 0) {
		int temp = new_a%new_b;
		new_a = new_b;
		new_b = temp;
	}

	return 	new_a > 0 ? new_a : -new_a;
}

void solution() {
	int C, N;

	// basic line
	map[1][1] = 1;
	map[0][1] = 1;
	map[1][0] = 1;

	for (int y = 1; y <= 1000; y++) {
		for (int x = 1; x < y; x++) {
			int gcd_val = gcd(y, x);

			if (gcd_val == 1) {
				map[y][x] = 1;
				map[x][y] = 1;
			}
			else {
				int new_y = y / gcd_val;
				int new_x = x / gcd_val;

				map[new_y][new_x] = 1;
				map[new_x][new_y] = 1;
			}
		}
	}

	cout << "hello\n";

	cin >> C;

	for (int i = 0; i < C; i++) {
		cin >> N;

		int count = 0;
		for (int y = 0; y <= N; y++) {
			for (int x = 0; x <= N; x++) {
				if (map[y][x]) count++;
			}
		}

		cout << count << "\n";
	}
	cout << "\n"; 
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	solution();

	return 0;
}
@changicho changicho added the not clear 진행중인 코드 label Jan 10, 2020
@changicho changicho added this to the day5 milestone Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not clear 진행중인 코드
Projects
None yet
Development

No branches or pull requests

1 participant