↓あとで (accepted in practice)
VI make_primes(int N) { // return all prime numbers less than N memory: O(N) time: O(N^2)? VI p(N, 1), out; for(int i=2;i<N;i++) if(p[i]) { out.push_back(i); for(int j=i*2;j<N;j+=i) p[j]=0; } return out; } VI primes; pair<ll, ll> f(int n) { ll out = 0LL; REP(ii, primes.size()) { int i=primes.size()-1-ii; int odd = 0; while(n % primes[i] == 0) { n/=primes[i]; odd = 1 - odd; } out = (out << 1) | odd; } return MP(n, out); } class TheSquareRootDilemma { public: int countPairs(int N, int M) { primes = make_primes(290); map<pair<ll, ll>, ll> ms; RANGE(i, 1, M+1) { ms[f(i)]++; } ll ans = 0; RANGE(i, 1, N+1) { ans += ms[f(i)]; } return ans; } };