Advertisement
a53

NewYork

a53
Apr 20th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("nyk.in");
  5. ofstream fout("nyk.out");
  6. struct oras
  7. {
  8. int lo, v[1005];
  9. };
  10. oras str[1005];
  11. int n, gcd, gcdmax, nrcasa, casamax, nrgcdm;
  12. int gcd_all(int a, int b)
  13. {
  14. if(a == 0)
  15. return b;
  16. return gcd_all(b % a, a);
  17. }
  18. int prime(int nr)
  19. {
  20. if(nr==2)
  21. return 1;
  22. if(nr<2)
  23. return 0;
  24. if(nr%2==0)
  25. return 0;
  26. for(int d=3; d*d<=nr; ++d)
  27. if(nr%d==0)
  28. return 0;
  29. return 1;
  30. }
  31. int main()
  32. {
  33. fin>>n;
  34. for(int i=1; i<=n; ++i)
  35. {
  36. fin>>str[i].lo>>str[i].v[1];
  37. gcd=str[i].v[1];
  38. for(int j=2; j<=str[i].lo; ++j)
  39. {
  40. fin>>str[i].v[j];
  41. gcd=gcd_all(gcd, str[i].v[j]);
  42. }
  43. if(gcd>=gcdmax)
  44. {
  45. gcdmax=gcd;
  46. nrgcdm=i;
  47. }
  48. }
  49. for(int i=1; i<=str[nrgcdm].lo; ++i)
  50. if(prime(str[nrgcdm].v[i]))
  51. if(str[nrgcdm].v[i] >= casamax)
  52. {
  53. casamax=str[nrgcdm].v[i];
  54. nrcasa=i;
  55. }
  56. if(nrcasa)
  57. fout<<nrgcdm<<" "<<nrcasa<<'\n'<<casamax;
  58. else
  59. fout<<"Nu am gasit casa!";
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement