백준 알고리즘 1769번 : 3의 배수

Zoo Da·2021년 11월 30일
0

백준 알고리즘

목록 보기
272/337
post-thumbnail

링크

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

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 F(int x){
  int ret = 0;  
  while(x != 0){
    ret += x % 10;
    x /= 10; 
  }
  return ret;
}

int32_t main() {
  fastio;
  int n,cnt = 0; cin >> n;
  while(n >= 10){
    n = F(n);
    cnt++;
  }
  cout << cnt << "\n";
  cout << (n == 3 || n == 6 || n == 9 ? "YES" : "NO") << "\n";
}
profile
메모장 겸 블로그

0개의 댓글