当前位置:
首页 >
PAT甲级1152 Google Recruitment :[C++题解]判质数
发布时间:2025/4/5
44
豆豆
生活随笔
收集整理的这篇文章主要介绍了
PAT甲级1152 Google Recruitment :[C++题解]判质数
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
文章目录
- 题目分析
- 题目来源
题目分析
来源:acwing
分析:判质数,10位以内。
ac代码
#include<bits/stdc++.h> using namespace std;int n , k; bool is_prime(int n){if(n <= 1) return false;for(int i = 2; i<= n/i; i++)if(n %i ==0) return false;return true; }int main(){cin >> n >> k;string s;cin >> s;bool find = false;string t;for(int i = 0; i<n;i ++){if(i+k<=n){t = s.substr(i,k);if(is_prime(stoi(t))){find = true;break;}} }if(find) cout<<t<<endl;else cout<<"404"<<endl;}如果出现运行时错误,大多数是数组越界。
题目来源
PAT甲级1152 Google Recruitment
https://www.acwing.com/problem/content/1648/
总结
以上是生活随笔为你收集整理的PAT甲级1152 Google Recruitment :[C++题解]判质数的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: PAT甲级1116 Come on! L
- 下一篇: PAT甲级1008 Elevator:[