local ffi = require "ffi";

ffi.cdef[[
typedef struct {
	int x;
	int y;
	int z;
	int w;
	int t;
} vec5;
]]

local mt = {}
mt.__index = mt

function mt:incx()
  self.x = self.x + 1;
end
function mt:incy()
  self.y = self.y + 1;
end
function mt:incz()
  self.z = self.z + 1;
end
function mt:incw()
  self.w = self.w + 1;
end
function mt:d3()
  return self.w % 3 == 0;
end
function mt:d5()
  return self.w % 5 == 0;
end
function mt:d7()
  return self.w % 7 == 0;
end

local maker = ffi.metatype("vec5", mt)
local function newvec5(x, y, z, w)
  return maker(x, y, z, w, 0);
end

local function main(num)
	local c = newvec5(0, 0, 0, 0);
	while (c.w < num) do
		local d3, d5, d7 = c:d3(), c:d5(), c:d7();
		c.t = d3;
		c.x = c.x + c.t;
		c.t = ((not d3) and d5);
		c.y = c.y + c.t;
		c.t = ((not d3) and (not d5) and d7);
		c.z = c.z + c.t;
		c:incw();
	end
	return tonumber(c.z), tonumber(c.x), tonumber(c.y);
end

local n = tonumber(...);
local c7, c3, c5 = main(n);
print("c7: "..c7.." c3: "..c3.." c5: "..c5);
