-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
32 lines (30 loc) · 761 Bytes
/
program.cpp
File metadata and controls
32 lines (30 loc) · 761 Bytes
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
#include "../include/pre.h"
int bulbSwitchSlow(int n)
{
std::vector<bool> bulbs(n);
for (auto& i : bulbs) i = false;
int t = 0;
while (++t <= n) {
for (size_t i = 0; i != bulbs.size(); i++)
if ((i + 1) % t == 0) bulbs[i] = !bulbs[i];
}
return std::count_if(bulbs.begin(), bulbs.end(), [](bool v){return v;});
}
int bulbSwitch(int n)
{
//return static_cast<int>(std::sqrt(n));
return static_cast<int>(std::ceil(std::sqrt(n + 1) - 1));
}
int main()
{
int n = 0;
//while (++n != 200) cout << n << ":\t" << bulbSwitchSlow(n) << endl;
while (++n != 1000)
{
if (bulbSwitchSlow(n) != bulbSwitch(n)) {
cout << n << "\tERROR";
return 1;
}
}
return 0;
}