SumaPrimosCantidad

Zaid · December 30, 2020 · C++
#include <iostream>
using namespace std;
int c,primo,n,i,s=0,cant=0;
int main(int argc, char *argv[]) {
	cin>>n;
	for(i=2; i<=n; i++){
		primo=1;
		c=2;
		while((c<=i/2) && primo){
			if(i%c==0)
				primo=0;
			c++;
		}
		if(primo){
			s+=i;
			cant+=primo;
		}
	}
	cout<<cant<<" "<<s;
	return 0;
}

Comments

Please sign up or log in to contribute to the discussion.