Last active
October 7, 2021 14:47
-
-
Save luciocf/b1384bf666e403998bf15dba64bc4e96 to your computer and use it in GitHub Desktop.
Comentário NOIC - OBI Fase 3 P2 - Cubo e quadrado
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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