• Source
    1. #include <iostream>
    2. #include <vector>
    3. using namespace std;
    4.  
    5. int arr[10];
    6. long long N;
    7. long long Value [10], n, k;
    8.  
    9. void read ()
    10. {
    11. cin>>N;
    12. for (int i=1; i<=5; i++)
    13. {
    14. cin>>Value[i];
    15. }
    16. }
    17.  
    18. vector <long long> v[10];
    19. void tinh ()
    20. {
    21. long long S = 1;
    22. int count1=0;
    23. for (int i=1; i<=n; i++)
    24. {
    25. if (arr[i]==1)
    26. {
    27. count1++;
    28. S*=Value[i];
    29. }
    30. }
    31. if (count1!=0)
    32. {
    33. long long tmp = N/S;
    34. v[count1].push_back(tmp);
    35. }
    36. }
    37.  
    38. void sinhNP (int u)
    39. {
    40. if (u>n)
    41. {
    42. tinh ();
    43. }
    44. else
    45. {
    46. for (int i=0; i<=1; i++)
    47. {
    48. arr[u]=i;
    49. sinhNP (u+1);
    50. }
    51. }
    52. }
    53.  
    54. int main ()
    55. {
    56. int t;
    57. cin>>t;
    58. while (1)
    59. {
    60. if (t==0) break;
    61. t--;
    62. read ();
    63. n=5;
    64. sinhNP (1);
    65. long long SUM = 0;
    66. for (int i=1; i<=5; i++)
    67. {
    68. for (int j=0; j<v[i].size (); j++)
    69. {
    70. if (i%2!=0) SUM+=v[i][j];
    71. else SUM-=v[i][j];
    72. }
    73. }
    74. cout<<N-SUM<<endl;
    75.  
    76. //Xoa du lieu truoc do.
    77. for (int i=1; i<=5; i++)
    78. v[i].clear();
    79. }
    80. return 0;
    81. }