Advertisement
leminhkt

noname32

Mar 31st, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define lFOR(i, a, b) for(ll i=(a); i<=(b); i++)
  5. #define lFORn(i, n) for(ll i=1; i<=(n); i++)
  6. #define lFORx(i, a, b, n) for(ll i=(a); i<=(b); i+=(x))
  7. #define FORa(i, b) for(i; i<=(b); i++)
  8. #define FORax(i, b, x) for(i; i<=(b); i+=(x))
  9. #define lFORR(i, a, b) for(ll i=(a); i>=(b); i--)
  10. #define lFORRn(i, n) for(ll i=(n); i>=1; i--)
  11. #define lFORRx(i, a, b, n) for(ll i=(a); i>=(b); i-=(x))
  12. #define FORRa(i, b) for(i; i>=(b); i--)
  13. #define FORRax(i, b, x) for(i; i>=(b); i-=(x))
  14. #define iFOR(i, a, b) for(int i=(a); i<=(b); i++)
  15. #define iFORn(i, n) for(int i=1; i<=(n); i++)
  16. #define iFORx(i, a, b, n) for(int i=(a); i<=(b); i+=(x))
  17. #define iFORR(i, a, b) for(int i=(a); i>=(b); i--)
  18. #define iFORRn(i, n) for(int i=(n); i>=1; i--)
  19. #define iFORRx(i, a, b, n) for(int i=(a); i>=(b); i-=(x))
  20. #define pb(x) push_back(x)
  21. #define all(x) (x).begin(), (x).end()
  22. #define sz(x) (x).size()
  23. #define sqr(x) (ll)(x)*(x)
  24. #define PI (2*acos(0))
  25. using namespace std;
  26.  
  27. template <typename T>
  28. inline void Read(T& x)
  29. {
  30.     bool Neg = false;
  31.     char c;
  32.     for (c = getchar(); c < '0' || c > '9'; c = getchar())
  33.         if (c == '-') Neg = !Neg;
  34.     x = c - '0';
  35.     for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
  36.         x = x * 10 + c - '0';
  37.     if (Neg) x = -x;
  38. }
  39. template <typename T>
  40. inline void Write(T x)
  41. {
  42.     if (x < 0)
  43.     {
  44.         putchar('-'); x = -x;
  45.     }
  46.     T p = 1;
  47.     for (T temp = x / 10; temp > 0; temp /= 10) p *= 10;
  48.     for (; p > 0; x %= p, p /= 10) putchar(x / p + '0');
  49. }
  50.  
  51. void update(int* n){
  52.     *n=(*n<4)?((*n==2)?3:5):((*n-1)%6)?(*n+2):(*n+4);
  53. }
  54. bool cprm(int n){
  55.     if(n==2||n==3) return 1;
  56.     if(n<2||n%2==0||n%3==0) return 0;
  57.     for(int i=5; i<=sqrt(n); update(&i)) if(n%i==0) return 0;
  58.     return 1;
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.         //=================declare=================
  67.     struct lmao{
  68.         int val, ntrg;
  69.     };
  70.     lmao n;
  71.     int a, b, dem;
  72.  
  73.  
  74.  
  75.  
  76. //=================..end..=================
  77.         //=================function=================
  78.     int calc(int x){
  79.         if(x==1) return 0;
  80.         int s=0;
  81.         for(int i=2; x-1; update(&i)){
  82.             if(x%i==0){
  83.                 s+=i;
  84.                 while(x%i==0) x/=i;
  85.             }
  86.             if(cprm(x)) s+=x, x=1;
  87.         }
  88.         return s;
  89.     }
  90.  
  91.  
  92.  
  93.  
  94. //=================..end...=================
  95. int main(){
  96.     //freopen("INPUT.inp", "r", stdin);
  97.     //freopen("OUTPUT.out", "w", stdout);
  98.     //ios_base::sync_with_stdio(0); cin.tie(0);
  99.         //=================code=================
  100.     cout<<"Nhap n: "; cin>>n.val;
  101.     cout<<"So nguyen to rut gon cua n: "<<(n.ntrg=calc(n.val))<<'\n';
  102.     cout<<"Nhap a, b: "; cin>>a>>b;
  103.     cout<<"Cac so co cung so nguyen to voi n:\n";
  104.     iFOR(i, a, b) if(calc(i)==n.ntrg){
  105.         cout<<i<<' ';
  106.         dem++;
  107.     }
  108.     cout<<"\nCo "<<dem<<" so";
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //=================end.=================
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement