Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
- #define ll long long
- #define pb push_back
- #define endl "\n"
- const int mx = 1e8+123;
- bitset<mx> is_prime;
- vector<int> prime;
- void primegen ( int n )
- {
- n += 100;
- for ( int i = 3; i <= n; i += 2 ) is_prime[i] = 1;
- int sq = sqrt ( n );
- for ( int i = 3; i <= sq; i += 2 ) {
- if ( is_prime[i] == 1 ) {
- for ( int j = i*i; j <= n; j += ( i + i ) ) {
- is_prime[j] = 0;
- }
- }
- }
- is_prime[2] = 1;
- prime.push_back (2);
- for ( int i = 3; i <= n; i += 2 ) {
- if ( is_prime[i] == 1 ) prime.push_back ( i );
- }
- }
- ll SOD (ll l)
- {
- ll ret = 1;
- for ( auto p : prime ) {
- if ( 1LL * p * p > l ) break;
- if ( l % p == 0 ) {
- ll powP = p;
- while ( l % p == 0 ) {
- powP *= p;
- l/= p;
- }
- ret *= ( ( powP - 1 ) / ( p - 1 ) );
- }
- }
- if ( l > 1 ) {
- ret *= ( l + 1 );
- }
- return ret;
- }
- int main()
- {
- suni;
- primegen(1e8);
- int t;
- cin >> t;
- while ( t-- ) {
- ll n;
- cin >> n;
- cout << SOD (n) - n << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement