-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPE_Plus_064.cpp
More file actions
48 lines (42 loc) · 1.08 KB
/
PE_Plus_064.cpp
File metadata and controls
48 lines (42 loc) · 1.08 KB
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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int getPeriod(int n){
int top = 1, temptop;
int bot = (int) sqrt(n), tempbot;
int BOT = bot;
int count = 0;
do{
temptop = bot;
tempbot = n - bot * bot;
// cout << temptop << " " << tempbot << endl;
if(tempbot % top == 0){
tempbot /= top;
top = 1;
}
// cout << top << " " << tempbot << endl;
temptop %= tempbot;
temptop = abs(tempbot - temptop);
while(temptop + tempbot <= BOT)
temptop += tempbot;
top = tempbot;
bot = temptop;
count++;
// cout << top << " " << bot << endl << endl;
}while(top != 1 || bot != BOT);
return count;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n, tot = 0;
cin >> n;
for(int i = 2; i <= n; i++){
if(sqrt(i) == (int) sqrt(i)) continue;
if(getPeriod(i) % 2 == 1) tot++;
}
cout << tot;
return 0;
}