Skip to content

BOJ_2725_보이는 점의 개수 #46

Open

Description

@changicho

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;
}

Activity

  1. added this to the day5 milestone on Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    not clear진행중인 코드

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions