#20532: 不解


Easonsfriend (去寫./Problems?ownerid=89827)

學校 : 不指定學校
編號 : 89827
來源 : [106.105.188.90]
最後登入時間 :
2024-04-23 23:15:35
e795. p2.質數日 -- 2019年12月TOI新手同好會 | From: [106.105.188.90] | 發表日期 : 2020-02-04 02:59

#0: 5% WA (line:1)

您的答案為: 20031201 isn’t a Prime Day!
正確答案為: 20031201 isn't a Prime Day!

#1: 5% WA (line:1)

您的答案為: 20031211 isn’t a Prime Day!
正確答案為: 20031211 isn't a Prime Day!

#2: 5% WA (line:1)

您的答案為: 20031218 isn’t a Prime Day!
正確答案為: 20031218 isn't a Prime Day!

#3: 5% WA (line:1)

您的答案為: 20031225 isn’t a Prime Day!
正確答案為: 20031225 isn't a Prime Day!

#4: 5% WA (line:2)

您的答案為: 20010107 isn’t a Prime Day!
正確答案為: 20010107 isn't a Prime Day!

#5: 5% WA (line:5)

您的答案為: 20160107 isn’t a Prime Day!
正確答案為: 20160107 isn't a Prime Day!

#6: 5% WA (line:1)

您的答案為: 21370217 isn’t a Prime Day!
正確答案為: 21370217 isn't a Prime Day!

#7: 5% WA (line:1)

您的答案為: 21541024 isn’t a Prime Day!
正確答案為: 21541024 isn't a Prime Day!

#8: 5% WA (line:1)

您的答案為: 29390312 isn’t a Prime Day!
正確答案為: 29390312 isn't a Prime Day!

#9: 5% WA (line:1)

您的答案為: 20520721 isn’t a Prime Day!
正確答案為: 20520721 isn't a Prime Day!

#10: 5% WA (line:2)

您的答案為: 25320707 isn’t a Prime Day!
正確答案為: 25320707 isn't a Prime Day!

#11: 5% WA (line:1)

您的答案為: 26951018 isn’t a Prime Day!
正確答案為: 26951018 isn't a Prime Day!

#12: 5% WA (line:1)

您的答案為: 27120706 isn’t a Prime Day!
正確答案為: 27120706 isn't a Prime Day!

#13: 5% WA (line:1)

您的答案為: 26320422 isn’t a Prime Day!
正確答案為: 26320422 isn't a Prime Day!

#14: 5% WA (line:1)

您的答案為: 25530529 isn’t a Prime Day!
正確答案為: 25530529 isn't a Prime Day!

#15: 5% WA (line:1)

您的答案為: 26090303 isn’t a Prime Day!
正確答案為: 26090303 isn't a Prime Day!

#16: 5% WA (line:1)

您的答案為: 25300530 isn’t a Prime Day!
正確答案為: 25300530 isn't a Prime Day!

#17: 5% WA (line:1)

您的答案為: 25871104 isn’t a Prime Day!
正確答案為: 25871104 isn't a Prime Day!

#18: 5% WA (line:1)

您的答案為: 26430409 is a Prime Day!
正確答案為: 26430409 isn't a Prime Day!

#19: 5% WA (line:1)

您的答案為: 25640610 isn’t a Prime Day!
正確答案為: 25640610 isn't a Prime Day!


_____________________附上程式碼____________________________

#include <iostream>

using namespace std;

 

bool isPrime(string s){

    int n=0;

    for(int i=0;i<s.length();i++){

        n*=10;

        n+=s[i]-'0';

    }

    for(int i=2;i*i<n;i++){

        if(n%i==0)return false;

    }

    return true;

}

 

int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        string s1=s;

        bool flag=false;

        for(int i=0;i<s.length();i++){

            if(isPrime(s)){

                s[i]=0;

            }

            else{

                flag=true;

                break;

            }

        }

        if(flag)cout<<s1<<" isn’t a Prime Day!\n";

        else cout<<s1<<" is a Prime Day!\n";

    }

}

 




 
#20533: Re:不解


Easonsfriend (去寫./Problems?ownerid=89827)

學校 : 不指定學校
編號 : 89827
來源 : [106.105.188.90]
最後登入時間 :
2024-04-23 23:15:35
e795. p2.質數日 -- 2019年12月TOI新手同好會 | From: [106.105.188.90] | 發表日期 : 2020-02-04 03:08

#0: 5% WA (line:1)

您的答案為: 20031201 isn’t a Prime Day!
正確答案為: 20031201 isn't a Prime Day!

#1: 5% WA (line:1)

您的答案為: 20031211 isn’t a Prime Day!
正確答案為: 20031211 isn't a Prime Day!

#2: 5% WA (line:1)

您的答案為: 20031218 isn’t a Prime Day!
正確答案為: 20031218 isn't a Prime Day!

#3: 5% WA (line:1)

您的答案為: 20031225 isn’t a Prime Day!
正確答案為: 20031225 isn't a Prime Day!

#4: 5% WA (line:2)

您的答案為: 20010107 isn’t a Prime Day!
正確答案為: 20010107 isn't a Prime Day!

#5: 5% WA (line:5)

您的答案為: 20160107 isn’t a Prime Day!
正確答案為: 20160107 isn't a Prime Day!

#6: 5% WA (line:1)

您的答案為: 21370217 isn’t a Prime Day!
正確答案為: 21370217 isn't a Prime Day!

#7: 5% WA (line:1)

您的答案為: 21541024 isn’t a Prime Day!
正確答案為: 21541024 isn't a Prime Day!

#8: 5% WA (line:1)

您的答案為: 29390312 isn’t a Prime Day!
正確答案為: 29390312 isn't a Prime Day!

#9: 5% WA (line:1)

您的答案為: 20520721 isn’t a Prime Day!
正確答案為: 20520721 isn't a Prime Day!

#10: 5% WA (line:2)

您的答案為: 25320707 isn’t a Prime Day!
正確答案為: 25320707 isn't a Prime Day!

#11: 5% WA (line:1)

您的答案為: 26951018 isn’t a Prime Day!
正確答案為: 26951018 isn't a Prime Day!

#12: 5% WA (line:1)

您的答案為: 27120706 isn’t a Prime Day!
正確答案為: 27120706 isn't a Prime Day!

#13: 5% WA (line:1)

您的答案為: 26320422 isn’t a Prime Day!
正確答案為: 26320422 isn't a Prime Day!

#14: 5% WA (line:1)

您的答案為: 25530529 isn’t a Prime Day!
正確答案為: 25530529 isn't a Prime Day!

#15: 5% WA (line:1)

您的答案為: 26090303 isn’t a Prime Day!
正確答案為: 26090303 isn't a Prime Day!

#16: 5% WA (line:1)

您的答案為: 25300530 isn’t a Prime Day!
正確答案為: 25300530 isn't a Prime Day!

#17: 5% WA (line:1)

您的答案為: 25871104 isn’t a Prime Day!
正確答案為: 25871104 isn't a Prime Day!

#18: 5% WA (line:1)

您的答案為: 26430409 is a Prime Day!
正確答案為: 26430409 isn't a Prime Day!

#19: 5% WA (line:1)

您的答案為: 25640610 isn’t a Prime Day!
正確答案為: 25640610 isn't a Prime Day!


_____________________附上程式碼____________________________

#include

using namespace std;

 

bool isPrime(string s){

    int n=0;

    for(int i=0;i<s.length();i++){

        n*=10;

        n+=s[i]-'0';

    }

    for(int i=2;i*i<n;i++){

        if(n%i==0)return false;

    }

    return true;

}

 

int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        string s1=s;

        bool flag=false;

        for(int i=0;i<s.length();i++){

            if(isPrime(s)){

                s[i]=0;

            }

            else{

                flag=true;

                break;

            }

        }

        if(flag)cout<<s1<<" isn’t a Prime Day!\n";

        else cout<<s1<<" is a Prime Day!\n";

    }

}

 





喔我知道了

" ' "和" ’ "的問題

以AC了

 

 
ZeroJudge Forum