結果

問題 No.1747 Many Formulae 2
ユーザー woodsgreenwoodsgreen
提出日時 2022-01-05 15:25:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 1,849 ms
コンパイル使用メモリ 194,388 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 19:22:21
合計ジャッジ時間 2,674 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int isprime(long long int n){
    if(n<2) return 0;
    for(long long i=2;i*i<=n;i ++)
        if(n%i==0) return 0;
    return 1;
}
char s[20];
int n,m=1,a[20],ans;
long long v,k;
int main(){
    scanf("%s",s);
    n=strlen(s);
    for(int i=1;i<n;i++) m*=2;
    for(int i=0;i<m;++i){
        memset(a,0,sizeof(a));
        int j=0,x=i;
        while(x){
            a[j++]=x%2;
            x/=2;
        }
        k=s[0]-'0',v=0;
        for(int j=1;j<n;++j){
            if(a[j-1]){
                v+=k;
                k=0;
            }
            k=k*10+s[j]-'0';
        }
        v+=k;
//        printf("i=%d,a=[%d",i,a[0]);
//        for(int j=1;j<n-1;++j) printf(",%d",a[j]);
//        printf("],v=%lld\n",v);
        ans+=isprime(v);
    }
    printf("%d\n",ans);
    return 0;
}
0