Spoj ACPC10A solution

By | October 8, 2016

Spoj ACPC10A solution. Spoj Whats Next solution.

Category: AdHoc, Math, Formula

This question is based on direct application of Arithmetic Progression‘s common difference and Geometric Progression‘ common ratio.

First check whether there is a common difference (c-b) and (b-a) , or whether there is common ratio (c/b) and (b/a).

Spoj ACPC10A solution code:

#include <bits/stdc++.h>
using namespace std;

int main() {
   int a,b,c;

   //will stop if all 3 are zeros
   while(a!=0 || b!=0 || c!=0)
      //if the series is AP
      if((c-b) == (b-a))
         // c-b = common difference
         cout<<"AP "<<c+(c-b)<<"\n";
      //else it is GP
         // c/b = common ratio
         cout<<"GP "<<c*(c/b)<<"\n";
   return 0;