fork download
  1. #include <bits/stdc++.h>
  2. #include <iomanip>
  3. #include <iterator>
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. #include <ext/pb_ds/tree_policy.hpp>
  6. using namespace __gnu_pbds;
  7. #define ordered_set tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update>
  8. using namespace std;
  9. #define ll long long
  10. #define ld long double
  11. #define pb push_back
  12. #define all(a) a.begin(), a.end()
  13. #define death ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  14. #define sz(x) ((int)(x).size())
  15. #define el "\n"
  16. #define basmala freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  17. #define int ll
  18. /****************************************************************************/
  19. int dx[] = {0, 0, 1, -1};
  20. int dy[] = {1, -1, 0, 0};
  21. int di[] = {1, 1, 1, 0, 0, -1, -1, -1};
  22. int dj[] = {1, 0, -1, 1, -1, 1, 0, -1};
  23. ll mod = 1e9 + 7;
  24. const int N = 1e6 + 8;
  25. vector<int>spf(N);
  26. /****************************************************************************/
  27. void pre(){
  28. iota(spf.begin(),spf.end(),0);
  29. for(int i=2;i*i<N;i++){
  30. if(spf[i]==i){
  31. for(int j=i*i;j<N;j+=i)
  32. spf[j]=min(spf[j],i);
  33. }
  34. }
  35. }
  36. int fastpow(int base, int pow)
  37. {
  38. if (base == 1 or pow == 0)
  39. return 1;
  40. int ret = fastpow(base, pow / 2);
  41. ret = (1ll * ret * ret) % mod;
  42. if (pow & 1)
  43. ret = (1ll * ret * base) % mod;
  44. return ret;
  45. }
  46. int fun(vector<int> &a) {
  47. int sum = 0;
  48. for (int i : a) {
  49. int div=i/spf[i];
  50. int term1 = fastpow(2, i);
  51. int term2 = fastpow(2,div);
  52. sum = ((sum%mod)+(term1%mod)-(term2%mod)+mod)%mod;
  53. }
  54. return sum;
  55. }
  56. /****************************************************************************/
  57. void neverland() {
  58. int n; cin>>n;
  59. vector<int>a;
  60. for(int i=0,x;i<n;i++)
  61. cin>>x,a.pb(x);
  62. cout<<fun(a)<<el;
  63. }
  64.  
  65. signed main() {
  66. // basmala;
  67. death;
  68. int t = 1; // cin >> t;
  69. pre();
  70. while (t--) {
  71. neverland();
  72. }
  73. }
  74.  
Success #stdin #stdout 0.01s 11152KB
stdin
3

2 9 10
stdout
1498