Skip to content

Instantly share code, notes, and snippets.

@luciocf
Last active October 7, 2021 14:47
Show Gist options
  • Save luciocf/b1384bf666e403998bf15dba64bc4e96 to your computer and use it in GitHub Desktop.
Save luciocf/b1384bf666e403998bf15dba64bc4e96 to your computer and use it in GitHub Desktop.
Comentário NOIC - OBI Fase 3 P2 - Cubo e quadrado
// Comentário NOIC - OBI Fase 3 P2 - Cubo e quadrado
// Complexidade: O(cbrt(B))
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
int a, b;
scanf("%d %d", &a, &b);
int ans = 0;
for (int k = 1; 1ll*k*k*k <= 1ll*b; k++) // enquanto k^3 <= B
{
int x = k*k*k;
if (x < a) continue; // checamos se k^3 >= A
int sq = (int)sqrt(x); // parte inteira da raíz quadrada de k^3
if (sq*sq == x) ans++; // se sq^2 = k^3, então k^3 é quadrado perfeito
}
printf("%d\n", ans);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment