fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ii pair<int, int>
  4. #define all(v) v.begin(), v.end()
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define ll long long
  9. #define ull unsigned long long
  10. #define TASK "1"
  11.  
  12. using namespace std;
  13.  
  14. const int N = 99999990;
  15. const ll oo = 1e18;
  16. const int mod = 1e9 + 7;
  17.  
  18. const char idx[27] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  19.  
  20. int f[N], s[N];
  21. vector<int> v;
  22.  
  23. int p(int n)
  24. {
  25. int cnt = 1;
  26. for(auto i : v){
  27. if(i * i > n) break;
  28. int cur = 0;
  29. if(n % i == 0){
  30. while(n % i == 0) n /= i, cur++;
  31. cnt *= (cur + 1);
  32. }
  33. }
  34. if(n != 1) cnt <<= 1;
  35. return cnt;
  36. }
  37.  
  38. int main(){
  39. ios_base::sync_with_stdio(false);
  40. cin.tie(NULL);
  41. cout.tie(NULL);
  42.  
  43. if(fopen(TASK".inp", "r")){
  44. freopen(TASK".inp", "r", stdin);
  45. freopen(TASK".out", "w", stdout);
  46. }
  47.  
  48. int n;
  49. cin >> n;
  50. ll res = 0;
  51. for (int i = 2; i * i <= 10000; i++){
  52. if(!s[i]){
  53. for(int j = i * i; j <= 10000; j += i){
  54. s[j] = true;
  55. }
  56. }
  57. }
  58. for (int i = 2; i <= 10000; i++) if(!s[i]) v.pb(i);
  59. while(n--){
  60. int a;
  61. cin >> a;
  62. if(!f[a]) f[a] = p(a);
  63. res += 1LL * a * f[a];
  64. }
  65. cout << res;
  66. return 0;
  67. }
  68.  
Success #stdin #stdout 0s 5284KB
stdin
4
1 2 3 4
stdout
23