正文
增加 18 行删除 18 行
52 行未改动5354555657585960616263646566676869102 行未改动全部展开17217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223317 行未改动52 行未改动= \sum\limits_{k=1}^{n}[n|k^2]$$替换到原式上有$$\sum\limits_{y=0}^{n}y(\lfloor\sqrt{n(y+1)}\rfloor-\lfloor\sqrt{ny}\rfloor) + \sum\limits_{x=1}^{n}[n|x^2]\\=\sum\limits_{y=0}^{n-1}y(\lfloor\sqrt{n(y+1)}\rfloor-\lfloor\sqrt{ny}\rfloor) + \sum\limits_{x=1}^{n}[n|x^2]$$则$$ans= \\\sum\limits_{x=0}^{n-1}x(\lfloor\sqrt{n(x+1)}\rfloor-\lfloor\sqrt{nx}\rfloor) + \sum\limits_{x=1}^{n}[n|x^2]+\sum\limits_{x=1}^{n} \lfloor\sqrt{nx}\rfloor\\102 行未改动全部展开vec <int> prime;void Euler (int N) {memset (isp, 1, sizeof isp);isp[0] = isp[1] = 0;for (int i = 2; i <= N; ++i) {if (isp[i])prime.pb (i);for (int j = 0; j < sz (prime) && i * prime[j] <= N; ++j) {isp[i * prime[j]] = 0;if (i % prime[j] == 0)break;}}}int T;signed main () {Euler (1e6);read (T);while (T--) {ll n; read (n);ll ans = (n % mod) * (n % mod) % mod, mul = 1;for (const auto & p : prime) {int cnt = 0;while (n % p == 0)n /= p, ++cnt;func <int (ll, int)> ksm = [] (ll a, int b) {ll res = 1;for (; b; b >>= 1, a = a * a % mod)if (b & 1) res = res * a % mod;return res;};(mul *= ksm (p, cnt / 2)) %= mod;}ll sqr = sqrtl (n);auto chkp = [] (ll x) -> bool {for (ll i = 2; i * i <= x; ++i)if (x % i == 0)return 1;return 0;};if (sqr * sqr == n) {(mul *= sqr) %= mod;}printf ("%lld\n", (ans + mul) % mod);}return 0;}17 行未改动52 行未改动5354555657585960616263646566676869102 行未改动全部展开17217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223317 行未改动52 行未改动= \sum\limits_{k=1}^{n}[n|k^2]$$替换到原式上有$$\sum\limits_{y=0}^{n}y(\lfloor\sqrt{n(y+1)}\rfloor-\lfloor\sqrt{ny}\rfloor) + \sum\limits_{x=1}^{n}[n|x^2]\\=\sum\limits_{y=0}^{n-1}y(\lfloor\sqrt{n(y+1)}\rfloor-\lfloor\sqrt{ny}\rfloor) + \sum\limits_{x=1}^{n}[n|x^2]$$则$$ans= \\\sum\limits_{x=0}^{n-1}x(\lfloor\sqrt{n(x+1)}\rfloor-\lfloor\sqrt{nx}\rfloor) + \sum\limits_{x=1}^{n}[n|x^2]+\sum\limits_{x=1}^{n} \lfloor\sqrt{nx}\rfloor\\102 行未改动全部展开vec <int> prime;void Euler (int N) {memset (isp, 1, sizeof isp);isp[0] = isp[1] = 0;for (int i = 2; i <= N; ++i) {if (isp[i])prime.pb (i);for (int j = 0; j < sz (prime) && i * prime[j] <= N; ++j) {isp[i * prime[j]] = 0;if (i % prime[j] == 0)break;}}}int T;signed main () {Euler (1e6);read (T);while (T--) {ll n; read (n);ll ans = (n % mod) * (n % mod) % mod, mul = 1;for (const auto & p : prime) {int cnt = 0;while (n % p == 0)n /= p, ++cnt;func <int (ll, int)> ksm = [] (ll a, int b) {ll res = 1;for (; b; b >>= 1, a = a * a % mod)if (b & 1) res = res * a % mod;return res;};(mul *= ksm (p, cnt / 2)) %= mod;}ll sqr = sqrtl (n);auto chkp = [] (ll x) -> bool {for (ll i = 2; i * i <= x; ++i)if (x % i == 0)return 1;return 0;};if (sqr * sqr == n) {(mul *= sqr) %= mod;}printf ("%lld\n", (ans + mul) % mod);}return 0;}17 行未改动