본문 바로가기

Algorithm_BOJ(백준)/완전탐색(Brute Force)

[백준 9094 c++ V] 수학적 호기심

728x90
반응형

- 풀이 원본: https://github.com/xhaktmchl/Algorithm_study/blob/main/BOJ/%EB%B8%8C%EB%A3%A8%ED%8A%B8%ED%8F%AC%EC%8A%A4(Brute_Force)/%5B%EB%B0%B1%EC%A4%80%209094%20c%2B%2B%20V%5D%20%EC%88%98%ED%95%99%EC%A0%81%20%ED%98%B8%EA%B8%B0%EC%8B%AC.cpp 

 

GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이

알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.

github.com

#include <iostream>
#include <algorithm>
using namespace std;
/*
[백준 9094 c++ V] 수학적 호기심
문제:
접근1: 
풀이: 
*/
int cnt, n, m, t, a, b;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> t;  //테스트 케이스 입력
    while (t)
    {
        t--;
        cnt = 0;
        cin >> n >> m;
        for (a = 1; a < n; a++)  //1부터 n까지 하나하나 다 해본다.
        {
            for (b = a + 1; b < n; b++)
            {
                if (!((a * a + b * b + m) % (a * b)))  //나눠서 나머지가 없으면 정수이므로 카운트해준다.
                    cnt++;
            }
        }
        cout << cnt << endl;
    }
}
반응형