您的答案為: 20031201 isn’t a Prime Day! 正確答案為: 20031201 isn't a Prime Day!
您的答案為: 20031211 isn’t a Prime Day! 正確答案為: 20031211 isn't a Prime Day!
您的答案為: 20031218 isn’t a Prime Day! 正確答案為: 20031218 isn't a Prime Day!
您的答案為: 20031225 isn’t a Prime Day! 正確答案為: 20031225 isn't a Prime Day!
您的答案為: 20010107 isn’t a Prime Day! 正確答案為: 20010107 isn't a Prime Day!
您的答案為: 20160107 isn’t a Prime Day! 正確答案為: 20160107 isn't a Prime Day!
您的答案為: 21370217 isn’t a Prime Day! 正確答案為: 21370217 isn't a Prime Day!
您的答案為: 21541024 isn’t a Prime Day! 正確答案為: 21541024 isn't a Prime Day!
您的答案為: 29390312 isn’t a Prime Day! 正確答案為: 29390312 isn't a Prime Day!
您的答案為: 20520721 isn’t a Prime Day! 正確答案為: 20520721 isn't a Prime Day!
您的答案為: 25320707 isn’t a Prime Day! 正確答案為: 25320707 isn't a Prime Day!
您的答案為: 26951018 isn’t a Prime Day! 正確答案為: 26951018 isn't a Prime Day!
您的答案為: 27120706 isn’t a Prime Day! 正確答案為: 27120706 isn't a Prime Day!
您的答案為: 26320422 isn’t a Prime Day! 正確答案為: 26320422 isn't a Prime Day!
您的答案為: 25530529 isn’t a Prime Day! 正確答案為: 25530529 isn't a Prime Day!
您的答案為: 26090303 isn’t a Prime Day! 正確答案為: 26090303 isn't a Prime Day!
您的答案為: 25300530 isn’t a Prime Day! 正確答案為: 25300530 isn't a Prime Day!
您的答案為: 25871104 isn’t a Prime Day! 正確答案為: 25871104 isn't a Prime Day!
您的答案為: 26430409 is a Prime Day! 正確答案為: 26430409 isn't a Prime Day!
您的答案為: 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";
}
}
您的答案為: 20031201 isn’t a Prime Day! 正確答案為: 20031201 isn't a Prime Day!
您的答案為: 20031211 isn’t a Prime Day! 正確答案為: 20031211 isn't a Prime Day!
您的答案為: 20031218 isn’t a Prime Day! 正確答案為: 20031218 isn't a Prime Day!
您的答案為: 20031225 isn’t a Prime Day! 正確答案為: 20031225 isn't a Prime Day!
您的答案為: 20010107 isn’t a Prime Day! 正確答案為: 20010107 isn't a Prime Day!
您的答案為: 20160107 isn’t a Prime Day! 正確答案為: 20160107 isn't a Prime Day!
您的答案為: 21370217 isn’t a Prime Day! 正確答案為: 21370217 isn't a Prime Day!
您的答案為: 21541024 isn’t a Prime Day! 正確答案為: 21541024 isn't a Prime Day!
您的答案為: 29390312 isn’t a Prime Day! 正確答案為: 29390312 isn't a Prime Day!
您的答案為: 20520721 isn’t a Prime Day! 正確答案為: 20520721 isn't a Prime Day!
您的答案為: 25320707 isn’t a Prime Day! 正確答案為: 25320707 isn't a Prime Day!
您的答案為: 26951018 isn’t a Prime Day! 正確答案為: 26951018 isn't a Prime Day!
您的答案為: 27120706 isn’t a Prime Day! 正確答案為: 27120706 isn't a Prime Day!
您的答案為: 26320422 isn’t a Prime Day! 正確答案為: 26320422 isn't a Prime Day!
您的答案為: 25530529 isn’t a Prime Day! 正確答案為: 25530529 isn't a Prime Day!
您的答案為: 26090303 isn’t a Prime Day! 正確答案為: 26090303 isn't a Prime Day!
您的答案為: 25300530 isn’t a Prime Day! 正確答案為: 25300530 isn't a Prime Day!
您的答案為: 25871104 isn’t a Prime Day! 正確答案為: 25871104 isn't a Prime Day!
您的答案為: 26430409 is a Prime Day! 正確答案為: 26430409 isn't a Prime Day!
您的答案為: 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了