Go: package main

import (
	"bufio"
	"os"
	"math"
	"strings"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

const (
	INF = 0x7FFFFFFF
	EPS = 1e-10
)

type Point struct {
	x, y float64
}
func (p *Point) plus(q *Point) *Point {
	return &Point{p.x + q.x, p.y + q.y}
}
func (p *Point) minus(q *Point) *Point {
	return &Point{p.x - q.x, p.y - q.y}
}
func (p *Point) multi(a float64) *Point {
	return &Point{p.x * a, p.y * a}
}
func (p *Point) div(a float64) *Point {
	return &Point{p.x / a, p.y / a}
}
func (p *Point) abs() float64 {
	return math.Sqrt(p.norm())
}
func (p *Point) norm() float64 {
	return p.x*p.x + p.y*p.y
}
func (p *Point) isLessThan(q *Point) bool {
	if p.x != q.x {
		return p.x < q.x && p.y < q.y
	}
	return true
}
func (p *Point) isEqual(q *Point) bool {
	return math.Abs(p.x - q.x) < EPS && math.Abs(p.y - q.y) < EPS
}

type Segment struct {
	p1, p2 *Point
}
func (s *Segment) norm() float64 {
	return (s.p2.x - s.p1.x)*(s.p2.x - s.p1.x) +
		(s.p2.y - s.p1.y)*(s.p2.y - s.p1.y)
}
func (s *Segment) abs() float64 {
	return math.Sqrt(s.norm())
}

func norm(a *Point) float64 {
	return a.x*a.x + a.y*a.y
}

func abs(a *Point) float64 {
	return math.Sqrt(norm(a))
}

func polar(a, r float64) *Point {
	return &Point{math.Cos(r)*a, math.Sin(r)*a}
}

func getDistance(a, b *Point) float64 {
	return abs(a.minus(b))
}

func dot(a, b *Point) float64 {
	return a.x*b.x + a.y*b.y
}

func cross(a, b *Point) float64 {
	return a.x*b.y - a.y*b.x
}

func getDistanceLP(s Segment, p *Point) float64 {
	return cross(s.p2.minus(s.p1), p.minus(s.p1))/ abs(s.p2.minus(s.p1))
}

func getDistanceSP(s Segment, p *Point) float64 {
	if dot(s.p2.minus(s.p1), p.minus(s.p1)) < 0 {
		return abs(p.minus(s.p1))
	}
	if dot(s.p1.minus(s.p2), p.minus(s.p2)) < 0 {
		return abs(p.minus(s.p2))
	}
	return getDistanceLP(s, p)
}

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		R, _ := strconv.Atoi(buf[0])
		N, _ := strconv.Atoi(buf[1])
		if R == 0 && N == 0 {
			break
		}
		p := make([]*Point, N)
		r := make([]float64, N)
		v := make([]float64, N)
		d := make([]float64, N)
		nd := make([]float64, N)
		die := make([]bool, N)
		for i := 0; i < N; i++ {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			_x, _ := strconv.ParseFloat(buf_[0], 64)
			_y, _ := strconv.ParseFloat(buf_[1], 64)
			_r, _ := strconv.ParseFloat(buf_[2], 64)
			_v, _ := strconv.ParseFloat(buf_[3], 64)
			tmp := &Point{_x, _y}
			p[i] = tmp
			r[i] = _r
			v[i] = _v
			nd[i] = getDistance(p[i], &Point{0, 0})
			d[i] = getDistance(p[i], &Point{0, 0})
			die[i] = false
		}
		for {
			for i := 0; i < N; i++ {
				nd[i] = math.Max(float64(R), nd[i]-v[i])
			}
			mini := float64(INF)
			id := -1
			for i := 0; i < N; i++ {
				if die[i] {
					continue
				}
				if nd[i] < EPS+float64(R) {
					continue
				}
				if nd[i] > mini {
					continue
				}
				mini = nd[i]
				id = i
			}
			if id == -1 {
				break
			}
			s := Segment{p[id], p[id]}
			s.p1 = s.p1.div(d[id])
			s.p1 = s.p1.multi(float64(R))
			s.p2 = s.p2.div(d[id])
			s.p2 = s.p2.multi(10000000.0)
			for i := 0; i < N; i++ {
				if nd[i] < EPS + float64(R) {
					continue
				}
				a := p[i]
				a = a.div(d[i])
				a = a.multi(nd[i])
				if getDistanceSP(s, a) < EPS + r[i] {
					die[i] = true
				}
			}
		}
		ans := 0
		for i := 0; i < N; i++ {
			if !die[i] {
				ans++
			}
		}
		fmt.Println(ans)
	}
}

C++: #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>


#define EPSILON 1e-9


#define ALL(x) (x).begin(), (x).end()


class point_t;


class vector_t {
public:
  double x;
  double y;
  double z;

public:
  vector_t(double x = 0, double y = 0, double z = 0) : x(x), y(y), z(z) {};

  vector_t(const point_t& p);

public:
  vector_t operator-() const {
    return vector_t(-x, -y, -z);
  };

  double operator*(const vector_t& v) const {
    return x * v.x + y * v.y + z * v.z;
  };

  vector_t operator*(double a) const {
    return vector_t(x * a, y * a, z * a);
  };

  vector_t operator/(double a) const {
    return vector_t(x / a, y / a, z / a);
  };

  vector_t operator^(const vector_t& v) const {
    return vector_t(y * v.z - z * v.y,
                    z * v.x - x * v.z,
                    x * v.y - y * v.x);
  };

public:
  double length() const {
    return sqrt(*this * *this);
  };

  vector_t normal() const {
    return *this / length();
  };
};


class point_t {
public:
  double x;
  double y;
  double z;
  double w;

public:
  point_t(double x = 0, double y = 0, double z = 0, double w = 1) : x(x), y(y), z(z), w(w) {};
  
public:
  point_t operator+(const vector_t& v) const {
    return point_t(x + v.x, y + v.y, z + v.z);
  };

  vector_t operator-(const point_t& p) const {
    return vector_t(x - p.x, y - p.y, z - p.z);
  };
};


vector_t::vector_t(const point_t& p) : x(p.x / p.w), y(p.y / p.w), z(p.z / p.w)
{
}


class point_circle_intersect : public std::unary_function<point_t, bool>
{
public:
  point_circle_intersect(const point_t& o, double r) : o_(o), rr_(r * r + EPSILON) {};

public:
  bool operator()(const point_t& p) const {
    vector_t v(p - o_);

    return v * v < rr_;
  };

private:
  point_t o_;
  
  double rr_;
};


class ray_circle_intersect : public std::binary_function<point_t, vector_t, bool>
{
public:
  ray_circle_intersect(const point_t& o, double r) : o_(o), rr_(r * r)
  {
  };

public:
  bool operator()(const point_t& o, const vector_t& d) {
    vector_t p(o - o_);

    double A = d * d;
    double B = d * p;
    double C = p * p - rr_;

    double D = B * B - A * C;

    if (D < 0)
      return false;
    
    D = sqrt(D);

    double t1 = (- B + D) / A;
    double t2 = (- B - D) / A;

    return ! (std::max(t1, t2) < -EPSILON);
  };

private:
  point_t o_;

  double rr_;
};


class point_point_squared_distance : public std::unary_function<point_t, double>
{
public:
  point_point_squared_distance(const point_t& p) : p_(p)
  {
  };

public:
  double operator()(const point_t& p) const {
    vector_t v(p - p_);

    return v * v;
  };

private:
  point_t p_;
};


template <class Operator>
class binary_coupler : public std::binary_function<int, int, bool>
{
public:
  binary_coupler(Operator op, const std::vector<point_t>& points) :
    op_(op), points_(points)
  {
  };

public:
  bool operator()(int a, int b) const {
    return op_(points_[a]) < op_(points_[b]);
  };

private:
  Operator op_;

  const std::vector<point_t>& points_;
};


template <class Operator>
binary_coupler<Operator> make_binary_coupler(Operator op, const std::vector<point_t>& points_)
{
  return binary_coupler<Operator>(op, points_);
}


int main(int argc, char** argv)
{
  while (1) {
    int r, n;
    
    std::cin >> r >> n;

    if (r == 0 && n == 0)
      break;
    
    std::vector<point_t>  points(n);
    std::vector<double>   rs    (n);
    std::vector<vector_t> vs    (n);
    std::vector<int>      valid (n, true);

    for (int i = 0; i < n; i ++) {
      double v;

      std::cin >> points[i].x >> points[i].y >> rs[i] >> v;

      vs[i] = - vector_t(points[i]).normal() * v;
    }

    std::vector<int> index(n);

    for (int i = 0; i < n; i ++)
      index[i] = i;

    int c = 0;

    for (int t = 1; ; t ++) {
      std::vector<point_t> pts(n);
      std::vector<int>     index;

      for (int i = 0; i < n; i ++)
        if (valid[i]) {
          point_t p(points[i] + vs[i] * t);

          if (point_circle_intersect(point_t(), r)(p)) {
            c ++;

            valid[i] = false;
          }
          else {
            pts[i] = p;

            index.push_back(i);
          }
        }

      if (index.empty())
        break;

      int im = std::min_element(ALL(index),
                                make_binary_coupler(point_point_squared_distance(point_t()),
                                                    pts)
                                ) - index.begin();

      for (int i = 0; i < n; i ++)
        if (valid[i])
          if (ray_circle_intersect(pts[i].x, pts[i].y)(point_t(), vector_t(pts[im])))
            valid[i] = false;
    }

    std::cout << c << std::endl;
  }

  return 0;
}