Skip to content

Instantly share code, notes, and snippets.

@hi2p-perim
Created January 17, 2015 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hi2p-perim/94cc7a0a105678c30cf6 to your computer and use it in GitHub Desktop.
Save hi2p-perim/94cc7a0a105678c30cf6 to your computer and use it in GitHub Desktop.
Composite numbers that Cocoa-chan should be careful to remember (cf. Gochiusa episode #10)
#include <iostream>
#include <vector>
int main()
{
for (int n = 2; n <= 9719; n++)
{
bool found = false;
int nn = n;
std::vector<int> a;
for (int i = 2; i*i < n; i++)
{
int v = 0;
while (nn % i == 0)
{
a.push_back(i);
nn /= i;
}
}
if (nn != 1) a.push_back(nn);
if (a.size() >= 2)
{
int cnt = 0;
for (int v : a)
{
// Assume that Cocoa-chan can instantly determine
// if a given number can be divisible by prime numbers smaller than 50
if (v > 50) cnt++;
}
if (cnt >= 2)
{
std::cout << n << " = ";
for (int v : a) std::cout << v << " ";
std::cout << std::endl;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment