diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-04-16 19:06:32 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-04-16 19:06:32 +0800 |
commit | ad4e2420e822b8a115aac6124307b89447578782 (patch) | |
tree | 6f4db875081597e2e64dd4221a97bbff25503dcc /1.5/ariprog.c | |
parent | a7721767628a51b752ad3a96eb334734241dcd8b (diff) | |
download | usaco-ad4e2420e822b8a115aac6124307b89447578782.tar.xz |
1.2~1.5
Diffstat (limited to '1.5/ariprog.c')
-rw-r--r-- | 1.5/ariprog.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/1.5/ariprog.c b/1.5/ariprog.c new file mode 100644 index 0000000..385fe8a --- /dev/null +++ b/1.5/ariprog.c @@ -0,0 +1,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; +} + |