fork download
  1. #include <cstdio>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. typedef pair <int,int> type;
  9.  
  10. vector <type> array;
  11.  
  12. bool cmp(type a,type b)
  13. {
  14. return a.first < b.first;
  15. }
  16.  
  17. void calc(int n)
  18. {
  19. int exp, q;
  20.  
  21. if(n%2==0)
  22. {
  23. exp = 0;
  24. while (n%2==0)
  25. {
  26. n /= 2;
  27. exp++;
  28. }
  29. array.push_back(make_pair(2,exp));
  30. }
  31. q = sqrt(n)+1;
  32. for(int i = 3; i < q&&n!=1; i+=2)
  33. {
  34. if (n%i==0)
  35. {
  36. exp = 0;
  37. while (n%i==0)
  38. {
  39. n /= i;
  40. exp++;
  41. }
  42. q = sqrt(n)+1;
  43. array.push_back(make_pair(i,exp));
  44. }
  45. }
  46. if(n!=1)
  47. {
  48. array.push_back(make_pair(n,1));
  49. }
  50.  
  51. }
  52.  
  53. int main()
  54. {
  55. int i, j, a, ans, tmp;
  56.  
  57. for(i = 0; i < 10; i++)
  58. {
  59. scanf("%d",&a);
  60. calc(a);
  61. }
  62. sort(array.begin(),array.end(),cmp);
  63. ans = 1;
  64. for(i = 0; i < array.size(); i++)
  65. {
  66. j = i;
  67. tmp = 1;
  68. while(j<array.size()&&array[j].first==array[i].first)
  69. {
  70. tmp += array[j++].second;
  71. }
  72. i = j-1;
  73. ans *= tmp;
  74. }
  75. printf("%d\n",ans%10);
  76. return 0;
  77. }
Success #stdin #stdout 0s 4240KB
stdin
1
2
6
1
3
1
1
1
1
1
stdout
9