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 <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
struct Ufo {
    Ufo(int a, int b, int c, int d) {
        x0 = a, y0 = b, r = c, v = d;
        dist0 = dist = std::sqrt(a * a + b * b);
    }
    int x0, y0, r, v;
    double dist0, dist;
    bool operator<(const Ufo& tar) const { return dist > tar.dist; }
};

int main() {
    std::vector<Ufo> ens;
    int r, n;
    while (std::cin >> r >> n && r && n) {
        rep(i, n) {
            int a, b, c, d;
            std::cin >> a >> b >> c >> d;
            ens.push_back(Ufo(a, b, c, d));
        }

        int count = 0;
        while (true) {
            for (auto& e : ens) e.dist -= e.v;
            std::sort(ens.begin(), ens.end());

            while (ens.size() && ens.back().dist <= r) {
                count++;
                ens.pop_back();
            }
            if (ens.size() == 0) break;

            int px = ens.back().x0, py = ens.back().y0;
            ens.pop_back();
            for (auto it = ens.begin(); it != ens.end();) {
                double p = it->dist * it->x0 / it->dist0;
                double q = it->dist * it->y0 / it->dist0;
                if (px * p + py * q > 0 &&
                    std::abs(py * p - px * q) / it->dist0 < it->r) {
                    it = ens.erase(it);
                } else
                    it++;
            }
        }
        std::cout << count << std::endl;

        ens.clear();
    }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#include <complex>
typedef complex<double> Point;
struct Line : public vector<Point> {
  Line(Point a, Point b){
    push_back(a); push_back(b);
  }
  Point vector() const {
    return back() - front();
  }
};
double dot(Point a, Point b){
  return real(conj(a) * b);
}
double cross(Point a, Point b){
  return imag(conj(a) * b);
}
int ccw(Point a, Point b, Point c){
  b -= a; c -= a;
  if(cross(b, c) > EPS) return +1;
  if(cross(b, c) < -EPS) return -1;
  if(dot(b, c) < 0) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}
bool intersectSS(const Line& s, const Line& t){
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 && 
         ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}
bool intersectSP(const Line& s, const Point& p){
  return ccw(s[0], s[1], p) == 0;
}
Point projection(const Line& l, const Point& p){
  double t = dot(p - l[0], l.vector()) / norm(l.vector());
  return l[0] + t * l.vector();
}
double distanceSP(const Line& s, const Point& p){
  const Point r = projection(s, p);
  if(intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const Line& s, const Line& t){
  if(intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
int main(){
  double R;
  int N;
  while(cin >> R >> N && (R != 0 || N != 0)){
    vector<Point> c(N);
    vector<double> r(N);
    vector<double> v(N);
    REP(i, N) cin >> c[i].real() >> c[i].imag() >> r[i] >> v[i];
    vector<bool> over(N);
    for(int t = 1; t <= 2 * N; t++){
      vector<Point> curr(N);
      REP(i, N) curr[i] = c[i] - min(1.0, v[i] * t / abs(c[i])) * c[i];
      int n_idx = -1;
      REP(i, N) if(!over[i] && abs(curr[i]) > R && (n_idx == -1 || abs(curr[n_idx]) > abs(curr[i]))) n_idx = i;
      if(n_idx == -1) break;
      Line laser(curr[n_idx] / abs(curr[n_idx]) * R, curr[n_idx] / abs(curr[n_idx]) * 1e6);
      REP(i, N) if(!over[i] && abs(curr[i]) > R && distanceSP(laser, curr[i]) < r[i] + EPS) over[i] = true;
    }
    int ans = 0;
    REP(i, N) if(!over[i]) ans ++;
    cout << ans << endl;
  }
  return 0;
}