Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. /**********************************************************************\
  2. |           _______  _     _____    ____   ___     _                   |
  3. |          |___   _|(_)   / ___/   / _  | |   \   | |                  |
  4. |              | |  | |  / /___   / /_| | | |\ \  | |                  |
  5. |           _  | |  | | /___  /  /  __  | | | \ \ | |                  |
  6. |           \ \| |  | | ___/ /  / /   | | | |  \ \| |                  |
  7. |            \___/  |_|/____/  /_/    |_| |_|   \___|                  |
  8. |                  Computer Science and Engineering                    |
  9. |  Bangabandhu Sheikh Mujibur Rahman Science and Technology University |
  10. |         devskill:jisancse||uva:jishan047||github:jisan047            |
  11. \**********************************************************************/
  12.  
  13.                 /********************\
  14.                 |                    |
  15.                 |    lets try.....   |
  16.                 |                    |
  17.                 \********************/
  18.  
  19. #include<bits/stdc++.h>
  20. //#include <ext/pb_ds/assoc_container.hpp>
  21.  
  22. using namespace std;
  23. //using namespace __gnu_pbds;
  24.  
  25. ////Policy based data structure
  26. //typedef tree<int, null_type, less<int>, rb_tree_tag,
  27. //             tree_order_statistics_node_update> pbdsset;
  28.  
  29. ///pre-processing
  30. #define     gcd(a, b)       __gcd(a,b)
  31. #define     lcm(a, b)       (a * b) / gcd(a, b)
  32. #define     loop(i, n)      for(int i=0;i<n;i++)
  33. #define     all(x)          x.begin(),x.end()
  34. #define     mem(a, x)       memset(a,x,sizeof a)
  35. #define     endl            '\n'
  36. #define     ss              second
  37. #define     ff              first
  38. #define     TN              typename
  39.  
  40. ///input functions
  41. int Int(){int x;scanf("%d",&x);return x;}
  42. long long Long(){long long x;scanf("%lld",&x);return x;}
  43. double Double(){double x;scanf("%lf",&x);return x;}
  44.  
  45. ///input functions shorting
  46. #define Int Int()
  47. #define Long Long()
  48. #define Double Double()
  49. #define Float Float()
  50.  
  51. ///Constants
  52. const int N = (int) 1e4 + 5;
  53. const long long MOD = (int) 1e9 + 7;
  54.  
  55. ///BitMask
  56. int Set(int a, int x){return (a |= (1 << x));}
  57. int Reset(int a, int x){return (a &= ~(1 << x));}
  58. bool Isset(int a, int x){return (bool) (a & (1 << x));}
  59.  
  60. //Trying to do something.
  61. //()()()()()()()()() ..... ()()()()()()()()()()()()
  62. //~~~~~~~~~~~~~~~~~~~~~~Get Ready~~~~~~~~~~~~~~~~~~~~~
  63.  
  64. ///debugger
  65.  
  66. ///end
  67.  
  68. // loading..................
  69.  
  70. int lp[N];
  71. vector<int> pr;
  72. int dp[N][N];
  73. int len;
  74. int solution(int i, int p){
  75.     if(i >= len) return -10000000;
  76.     if(p < 0) return -10000000;
  77.     if(!p)return 0;
  78.     if(~dp[i][p]) return dp[i][p];
  79.     return dp[i][p] = max(solution(i + 1, p), 1 + solution(i + 1, p - pr[i]));
  80. }
  81. int main(){
  82.     mem(dp, -1);
  83.     for(int i = 2; i < N; i++){
  84.         if(lp[i] == 0){
  85.             lp[i] = i;
  86.             pr.push_back(i);
  87.         }
  88.         for(int j = 0; j < (int)pr.size() and pr[j] <= lp[i] and i * pr[j] < N; j++){
  89.             lp[i * pr[j]] = pr[j];
  90.         }
  91.     }
  92.     len = pr.size();
  93.     int t = Int;
  94.     while(t--){
  95.         cout << max(0, solution(0, Int)) << endl;
  96.     }
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement