• Source
    1. #include<bits/stdc++.h>
    2. #define MAX 1000005
    3.  
    4. using namespace std;
    5.  
    6. bool check[MAX];
    7.  
    8. vector<int>primes;
    9.  
    10. int n,cntTwo,cntFive;
    11.  
    12. long long res;
    13.  
    14. void sieve()
    15. {
    16. int i,j;
    17.  
    18. primes.push_back(2);
    19.  
    20. for(i=3; i<=1000; i+=2)
    21. {
    22. for(j=i*i; j<MAX; j+=2*i)
    23. {
    24. check[j] = true;
    25. }
    26. }
    27.  
    28. for(i=3; i<MAX; i+=2)
    29. {
    30. if(check[i]==false)
    31. {
    32. primes.push_back(i);
    33. }
    34. }
    35. }
    36.  
    37. void solve()
    38. {
    39. cntTwo = 0;
    40.  
    41. cntFive = 0;
    42.  
    43. res = 1;
    44.  
    45. for(int i=0; primes[i]<=n; i++)
    46. {
    47. long long temp = 1;
    48.  
    49. if(primes[i]==2)
    50. {
    51. while(temp*2<=n)
    52. {
    53. cntTwo++;
    54.  
    55. temp*=2;
    56. }
    57. }
    58. else if(primes[i]==5)
    59. {
    60. while(temp*5<=n)
    61. {
    62. cntFive++;
    63.  
    64. temp*=5;
    65. }
    66. }
    67. else
    68. {
    69. while(temp*primes[i]<=n)
    70. {
    71. temp*=primes[i];
    72.  
    73. res*=primes[i];
    74.  
    75. res%=10;
    76. }
    77. }
    78. }
    79. }
    80.  
    81. int main()
    82. {
    83. sieve();
    84.  
    85. int i;
    86.  
    87. while(scanf("%d",&n)&&n)
    88. {
    89. solve();
    90.  
    91. for(i=1; i<=cntTwo-cntFive; i++)
    92. {
    93. res*=2;
    94.  
    95. res%=10;
    96. }
    97.  
    98. printf("%lld\n",res);
    99. }
    100.  
    101. return 0;
    102. }