summaryrefslogtreecommitdiff
path: root/1.5/ariprog.c
blob: 385fe8af063bc5b4b8b3603fa603905d2a4cff00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
ID: mytbk921
LANG: C
TASK: ariprog
*/

#include <stdio.h>

int squares[251];
int notpass[251*251*2+1]={};
int n,m;

int check(int x) //check if x is p^2+q^2
{
	int i,j;
	if (notpass[x]==1)
		return 0;
	if (notpass[x]==-1)
		return 1;
	for (i=0; i<=m&&squares[i]<=x/2; i++){
		for (j=m; j>=i; j--){
			if (squares[i]+squares[j]==x){
				notpass[x]=-1;
				return 1;
			}
			if (squares[i]+squares[j]<x)
				break;
		}
	}
	notpass[x]=1;
	return 0;
}

int test(int a, int b) //test if a to a+nb can pass the ckecks
{
//	printf("test %d %d\n",a,b);
	int i;
	for (i=0; i<=n; i++){
		if (!check(a)){
//			printf("%d failed\n",a);
			return 0;
		}
		a += b;
	}
	return 1;
}

int main()
{
	int a,b;
	int found=0;
	FILE *fin=fopen("ariprog.in","r");
	FILE *fout=fopen("ariprog.out","w");
	fscanf(fin, "%d%d", &n, &m);
	for (a=0;a<=m;a++)
		squares[a]=a*a;
	n--;
	fclose(fin);
	for (b=1; b*n<=squares[m]*2; b++){
		for (a=0; a+b*n<=squares[m]*2; a++){
			if (test(a,b)){
				fprintf(fout,"%d %d\n",a,b);
				found=1;
			}
		}
	}
	if (!found)
		fprintf(fout,"NONE\n");
	fclose(fout);
	return 0;
}