标签:i+1 sqrt bre math div highlight names cpp col
1013 数素数 (20分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805309963354112
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <vector> using namespace std; bool is_prime(int n) { int i; for(i=2;i<=(int)(sqrt(n)+0.5);i++) {if(n%i==0) break;} if(i>(int)(sqrt(n)+0.5)) return true; else return false; } int main() { int m,n,count=0; vector<int> vec; cin>>m>>n; for(int i=2;;i++) { if(is_prime(i)) count++; if(count>=m&&count<=n&&is_prime(i)) vec.push_back(i); if(count>n) break; } for(int i=0;i<vec.size();i++) { if((i+1)%10==0) cout<<" "<<vec[i]<<endl; else if(i%10==0) cout<<vec[i]; else cout<<" "<<vec[i]; } return 0; }
标签:i+1 sqrt bre math div highlight names cpp col
原文地址:https://www.cnblogs.com/jianqiao123/p/12253629.html