백준 알고리즘 6131번 : 완전 제곱수

Zoo Da·2021년 11월 28일
0

백준 알고리즘

목록 보기
269/337
post-thumbnail

링크

https://www.acmicpc.net/problem/6131

sol1) 구현

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int int64_t
using namespace std;

int _pow(int x,int n){
  int ret = 1;
  while(n){
    if(n & 1) ret *= x;
    n >>= 1;
    x *= x;
  }
  return ret;
}

int Sol(int n){
  int ret = 0;
  for(int a = 1; a <= 500; a++){
    for(int b = 1; b <= 500; b++){
      if(_pow(a, 2) == (_pow(b, 2) + n)) ret++;
    }
  }
  return ret;
}

int32_t main() {
  fastio;
  int n; cin >> n;
  cout << Sol(n) << "\n";
}

feat) 빠른 거듭제곱 알고리즘

profile
메모장 겸 블로그

0개의 댓글