結果

問題 No.1185 完全な3の倍数
ユーザー akane
提出日時 2020-08-22 15:14:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 805 bytes
コンパイル時間 2,611 ms
コンパイル使用メモリ 192,216 KB
最終ジャッジ日時 2025-01-13 09:23:15
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 TLE * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); i++)
using namespace std;
using ll = long long;

int ctoi(char x){
    return x - '0';
}



int main(){
    ios::sync_with_stdio(false);
    int N; cin>>N;

    ll ans = 0;
    ll t=10;
    // 2桁の特殊処理
    while(t<100){
        int a = t%10;
        int b = (t/10)%t;
        if((a+b)%3==0){
            ans ++;
        }
        if(t==N) break;
        t++;
    }

    if(N<100){
        cout << ans << endl; return 0;
    }

    for(int i=111; i<=N; i+=3){
        string s = to_string(i);
        bool flg=true;
        for(int j=0; j<s.size(); j++){
            if(ctoi(s[j])%3 != 0){
                flg=false;
                break;
            }
        }
        if(flg) ans++;
    }
    
    cout << ans << endl;
 

}
0