forked from Twiggecode/Integer-Sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Juggler Sequence.cpp
49 lines (35 loc) · 878 Bytes
/
Juggler Sequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// C++ implementation of Juggler Sequence
#include <iostream>
#include <cmath>
#include <math.h>
// This function prints the juggler Sequence
void printJuggler(long long n) {
long long a = n;
// print the first term
std::cout << a << " ";
// calculate terms until
// last term is not 1
while (a != 1)
{
long long b = 0;
// Check if previous term
// is even or odd
if (!(a % 2)){
// calculate next term
b = floor(sqrt(a));
}
else{
// for odd previous term
// calculate next term
b = floor(sqrt(pow(a, 3.0)));
}
std::cout << b << " ";
a = b;
}
}
// Driver Code
int main() {
int n;
std::cin >> n; // enter the starting number for the Sequence
printJuggler(n);
}