Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 13
- #include <iostream>
- #include <cmath>
- //Írjuk ki az összes ikerprímet, amely egy adott n értéknél kisebb!
- using namespace std;
- int main()
- {
- int n,i,c,d,b,e;
- cin>>n;
- for(i=1;i<=n;i++){
- c=1;
- d=1;
- for(b=2;b<=sqrt(i);b++)
- if(i%b==0) c=0;
- for(e=2;e<=sqrt(i+2);e++)
- if((i+2)%e==0) d=0;
- if(c==1 && d==1)
- cout<<i<<"---"<<i+2<<endl;}
- return 0;
- }
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14
- #include <iostream>
- #include <cmath>
- //14. Határozzuk meg egy szám prímosztóinak összegét!
- using namespace std;
- int main()
- {
- int a,b,c,d,e=0;
- cin>>a;
- for(b=2;b<=(a/2);b++){
- d=1;
- for(c=2;c<=sqrt(b);c++)
- if(b%c==0) d=0;
- if(a%b==0 && d==1)
- e=e+b;}
- cout<<"A prim osztok osszege--->"<<e;
- return 0;
- }
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 15
- #include <iostream>
- #include <cmath>
- //15. Számoljuk ki az olyan háromjegyű prímek összegét, amelyeknek fordítottja is prim.
- using namespace std;
- int main()
- {
- int a,c,d,g,h,i,x=0;
- for(a=100;a<=999;a++){
- g=1;
- i=1;
- d=a%10*100+a/10%10*10+a/100;
- for(c=2;c<=sqrt(a);c++){
- if(a%c==0)
- g=0;}
- for(h=2;h<=sqrt(d);h++){
- if(d%h==0)
- i=0;}
- if(g==1 && i==1)
- x=x+a;
- cout<<a<<endl;}
- cout<<"3jegyu primek osszege, melyek forditottja is prim--->"<<x;
- return 0;
- }
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Advertisement
Add Comment
Please, Sign In to add comment