Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <fstream>
- using namespace std;
- ifstream f("numere.txt");
- ofstream g("numere.out");
- int prim(int x)
- {
- int i;
- for (i=2;i<=sqrt(x);i++)
- if (x%i==0)
- return 1; // nu e prim
- return 0;
- }
- int palindrom(int x)
- {
- int nr=0,xx;
- xx=x;
- while (xx)
- {
- nr=nr*10+xx%10;
- xx/=10;
- }
- if (nr==x)
- return 1; // e ogl
- return 0;
- }
- int cmmdc(int a,int b)
- {
- int r;
- r=a%b;
- while(r)
- {
- a=b;
- b=r;
- r=a%b;
- }
- if (prim(b)==0)
- return 0;// cmmdc e prim
- return 1;// NU e prim cmmdc
- }
- int main()
- {
- int i,n,ok=0,a,b,ok2=0;
- f>>n;
- for (i=1;i<=n;i++)
- {
- f>>a>>b;
- if (palindrom(a)==1 && palindrom(b)==1)
- ok=1;
- if (cmmdc(a,b)==0)
- ok2=1;
- if (ok==1 && ok2==1)
- g<<a<<" "<<b<<" "<<'\n';
- }
- return 0;
- }
- /* in fisierul txt numere.txt se afla pe prima linie un nr nat "n" si pe urm n linii cate 2 numere nat. despartite prin cate-un spatiu.
- scrieti un program care citeste cele n perechi de numere si afiseaza cate dintre acestea (perechi) sunt palindrom si au cmmd nr prim.
- se vor folosi minim 3 subprograme pentru nr prim, palindrom, cmmdc
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement