Răspuns:
#include <iostream>
using namespace std;
int main()
{
int a,b;
int sum;
int prim[] ={2, 3, 5, 7};
cout<<"Dati limita a: "; cin>>a;
cout<<"Dati limita b: "; cin>>b;
for(int i=a;i<=b;i++){
for(int j=0;j<4;j++){
if(i%10==prim[j] || i == prim[j]){
sum = sum + i*i;
}
}
}
cout<<"\nRezultat: "<<sum;
return 0;
}
Verificare:
a=5, b=14
Numerele adunate: 5, 7, 12, 13;
Calcule: 5*5+7*7+12*12+13*13=387