Skip to content

Instantly share code, notes, and snippets.

@surinoel
Created July 14, 2019 11:54
Show Gist options
  • Save surinoel/4b1c4def5179b5148d9229d5f144266e to your computer and use it in GitHub Desktop.
Save surinoel/4b1c4def5179b5148d9229d5f144266e to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
bool ok[1000001];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long n, m;
cin >> n >> m;
for (long long i = 2; i*i <= m; i++) {
long long st;
if (n%(i*i) == 0) { // 시작점이 제곱수라면
st = n;
}
else { // 시작점이 제곱수가 아닐 시 나머지를 빼주고, 제곱수만큼 더해줘서 시작
st = n - (n%(i*i)) + i*i;
}
for (long long j = st; j <= m; j += i*i) {
ok[j - n] = true;
}
}
int ans = 0;
for (int i = 0; i <= m - n; i++) {
if (!ok[i]) ans += 1;
}
cout << ans << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment