解题思路:输入,判断是否大于1,写函数,输出
注意事项:1既不是质数也不是合数;
参考代码:
#include<iostream> #include <vector> #include <stdbool.h> using namespace std; bool isprime(int nember){ for(int i = 2; i < nember; i++){ if(nember % i == 0 && nember != i) return true; } return false; } int main() { int begin_member, end_member; int cnt = 0; cin >> begin_member >> end_member; begin_member < 2 ? begin_member = 2 : begin_member; for(begin_member; begin_member <= end_member; begin_member++){ if(!isprime(begin_member)){ cnt += begin_member; } } cout << cnt << endl; return 0; }
0.0分
1 人评分