Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("bookface.in");
- ofstream fout("bookface.out");
- const int MAX_N = 1000001;
- int N, nr, K, P[MAX_N];
- bitset <MAX_N> viz;
- void ciur()
- {
- for(int i = 2; i < MAX_N; ++i)
- {
- if(viz[i] == 0)
- {
- P[++K] = i;
- for(int j = i+i; j < MAX_N; j += i)
- viz[j] = 1;
- }
- }
- }
- inline long long pow(long long x, int p)
- {
- long long rez = 1;
- for(; p; p >>= 1) {
- if(p & 1) {
- rez *= x;
- }
- x *= x;
- }
- return rez;
- }
- long long solutie(int nr)
- {
- long long aux=nr*nr;
- long long sd=1;
- for(int j=1; j<=K && 1LL*P[j]*P[j]<=aux; ++j)
- {
- if(aux%P[j]) continue;
- int p=0;
- while(aux%P[j]==0)
- {
- aux/=P[j];
- p++;
- }
- long long p1=pow(P[j], p+1)-1;
- long long p2=1LL*(p1/(P[j]-1));
- sd*=1LL*p2;
- }
- if(aux > 1)
- sd*=(aux+1);
- return sd;
- }
- int main()
- {
- ciur();
- fin>>N;
- for(int i=1; i<=N; i++)
- {
- fin>>nr;
- fout<<solutie(nr)<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement