I think it's correct to assume that n= (g*m)-n -> 2n=g*m , and that for
r=2 all the possible combinations have the form g=m+1.
for example (letters are persons,rows are groups):
Code: Select all
a a b d
b c c e
d e f f
Code: Select all
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#ifdef _MSC_VER
typedef _int64 Long;
typedef _int32 Int;
typedef unsigned _int64 ULong;
typedef unsigned _int32 UInt;
#elif __GNUC__
typedef long long Long;
typedef long Int;
typedef unsigned long long ULong;
typedef unsigned long UInt;
#elif __BCPLUSPLUS__
typedef __int64 Long;
typedef __int32 Int;
typedef unsigned __int64 ULong;
typedef unsigned __int32 UInt;
#else
typedef long Long;
typedef int Int;
typedef unsigned long ULong;
typedef unsigned int UInt;
#endif
using namespace std;
main(void){
unsigned int n,i;
ULong x,d;
ULong f,c;
bool impar;
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in.txt", O_RDONLY);
close (1); open ("myprog.out.txt", O_WRONLY | O_CREAT | O_TRUNC, 0600);
#endif
scanf("%d\n",&n);
if(n==0) exit(0);
for(i=0;i<n;i++)
{
cin >> x;
d=2*x;
f=floor(sqrt(d));
c=ceil(sqrt(d));
if ((d==(c*f) && (c!=f) && (d>2)))
printf("Yes.\n",x);
else
printf("No.\n");
}
}