Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- bool isprime(int n) {
- if (n <= 1) return false;
- if (n == 2) return true;
- if (n % 2 == 0) return false;
- for (int i = 3; i <= sqrt(n); i += 2) {
- if (n % i == 0) {
- return false;
- }
- }
- return true;
- }
- vector<int> precomputeSumOfPrimes(int max_n) {
- vector<int> v(max_n + 1, 0);
- int sum = 0;
- for (int i = 2; i <= max_n; ++i) {
- if (isprime(i)) {
- sum += i;
- }
- v[i] = sum;
- }
- return v;
- }
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int t;
- cin >> t;
- vector<int> v = precomputeSumOfPrimes(1e6);
- while(t--){
- int n;
- cin>>n;
- if (isprime(n)) {
- cout << v[n ] * n << endl;
- } else {
- if(n%2==0){
- cout << 2 * n << endl;
- }
- else{
- int p=0;
- for( p=3;p*p<=n;p++){
- if(n%p==0)break;
- }
- cout<<v[p]*n<<endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment