Require Import Arith Psatz.

Definition divides (p n:nat) := exists q:nat, n = p*q.

Lemma divides_plus : forall p n m, divides p n -> divides p m -> divides p (n+m).
Proof.
  intros p n m [p' Hp'] [q' Hq'].
  unfold divides.
  exists (p'+q').
  rewrite Hp',Hq'.
  ring.
Qed.

Lemma divides_mult : forall p q n m, divides p n -> divides q m -> divides (p*q) (n*m).
Proof.
 intros p q n m [p' Hp'] [q' Hq'].
  exists (p'*q').
  subst; ring.
Qed.

Lemma divides_1_all : forall n:nat, divides 1 n.
Proof.
intros; exists n; ring.
Qed.

Lemma divides_itself : forall n:nat, divides n n.
Proof.
intros; exists 1; ring.
Qed.

Lemma divides_2 : forall n:nat, divides 2 (n * (n + 1)).
Proof.
  induction n.
  exists 0; ring.
  replace (S n * (S n + 1)) with (n*(n+1)+2*(n+1)) by ring.
  apply divides_plus.
  assumption.
  apply (divides_mult 2 1).
  apply divides_itself.  
  apply divides_1_all.
Qed.

Lemma proof : forall n:nat, divides 6 (n*n*n-n).
Proof.
  induction n.
  simpl; exists 0; reflexivity.
  simpl.
  replace (S n * S n * S n - S n) with ((n*n*n-n)+3*(n*(n+1))) by nia.
  apply divides_plus.
  assumption.
  apply (divides_mult 3 2).
  apply divides_itself.
  apply divides_2.
Qed.


