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 <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
double EPS=1e-10;
int INF=1e9;
struct dat{
      double d,v;
      dat(){}
      dat(double d,double v):d(d),v(v){}
      bool operator<(const dat &a)const{return d<a.d;}
};
int main(){
      int n,R;
      double x,y,r,v;
      while(cin>>R>>n&&(R||n)){
            vector<dat>V;
            REP(i,n){
                  cin>>x>>y>>r>>v;
                  V.PB((dat){sqrt(x*x+y+y)+r,v});
            }
            int ans=0;bool update=false;
            while(V.size()){
                  sort(ALL(V));
                  update=true;
                  REP(i,V.size()){
                        if(V[i].d>R){
                              update=false;
                              ans+=i;
                              REP(j,i+1){
                                    V.erase(V.begin());
                              }
                              break;
                        }
                  }
                  if(update){
                        ans+=V.size();
                        break;
                  }
                  REP(i,V.size()){
                        V[i].d-=V[i].v;
                  }
            }
            cout<<ans<<endl;
      }
}

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

struct P{
	double x, y;
	P operator+(const P p) const;
	P operator-(const P p) const;
};

P operator*(const double k, const P p){return {k * p.x, k * p.y};}
P P::operator+(const P p) const{return {x+p.x, y+p.y};}
P P::operator-(const P p) const{return {x-p.x, y-p.y};}

typedef P Vector;

const P ORIGIN_P = {0, 0};
const double EPS = 1e-10;

double abs(double d){
	return (d>0)?d:-d;
}

double abs(P p){
	return sqrt(p.x*p.x + p.y*p.y);
}

double dotProduct(Vector v1, Vector v2){return v1.x*v2.x + v1.y*v2.y;}
double crossProduct(Vector v1, Vector v2){return v1.x*v2.y - v1.y*v2.x;}

Vector createUnitVector(Vector v){
	double dist = abs(v);
	if(dist < EPS){
		return {0, 0};
	}
	return (1/dist) * v;
}

//直線ab上に点cはあるか
bool is_point_on_line(P a, P b, P c){
	return (crossProduct(b-a, c-a) < EPS &&
					dotProduct(b-a, c-a) > -EPS &&
					dotProduct(a-b, c-b) > -EPS);
}

//直線abと点P間の距離
double distance_line_p(P a, P b, P p){
	if(dotProduct(b-a, p-a) < EPS)return abs(p-a);
	if(dotProduct(a-b, p-b) < EPS)return abs(p-b);
	return abs(crossProduct(a-b, p)) / abs(a-b);
}
 
class UFO{
public:
	P p;
	double r, v;
	Vector unit_v;
	UFO(P _p, double _r, double _v);
};

UFO::UFO(P _p, double _r, double _v)
	:p(_p), r(_r), v(_v){
	unit_v = createUnitVector(p);
}

double R;
int n;

bool comp(const UFO& l_ufo, const UFO& r_ufo){
	return abs(l_ufo.p) < abs(r_ufo.p);
}

void shoot(std::vector<UFO> &uv){//最も近いUFOの中心に向けてLazerを発射する
	std::sort(uv.begin(), uv.end(), comp);
 
	UFO attacked_u = uv[0];
 
	for(int i=0;i<uv.size();i++){
		UFO u = uv[i];
		double dist = distance_line_p(ORIGIN_P, 100000 * attacked_u.unit_v, u.p);
		if(dotProduct(100000 * attacked_u.unit_v, u.p) > -EPS && dist < u.r + EPS){//破壊
			uv.erase(uv.begin() + i);
			i--;
		}
	}
}

void moveUFO(std::vector<UFO> &uv){//UFOの移動
	std::sort(uv.begin(), uv.end(), comp);

	int uv_size = uv.size();
	for(int i=0;i<uv_size;i++){
		UFO &u = uv[i];
		u.p = u.p - u.v * u.unit_v;
	}
}
 
int countUFO(std::vector<UFO> &uv){//生存確定したUFOの数を返す
	std::sort(uv.begin(), uv.end(), comp);

	int res = 0;
	for(int i=0;i<uv.size();i++){
		if(is_point_on_line(uv[i].p, uv[i].unit_v, ORIGIN_P) || abs(uv[i].p) < R + EPS){
			uv.erase(uv.begin() + i);
			i--;
			res++;
		}
	}
	return res;
}

int main(){
	while(std::cin >> R >> n, n){
		std::vector<UFO> uv;
		for(int i=0;i<n;i++){
			P p;
			double r, v;
			std::cin >> p.x >> p.y >> r >> v;
			UFO u(p, r, v);
			uv.push_back(u);
		}

		std::sort(uv.begin(), uv.end(), comp);

		int res = 0;//生き残ったUFO
		while(!uv.empty()){
			moveUFO(uv);
			res += countUFO(uv);
			shoot(uv);
		}

		std::cout << res << std::endl;
	}
}