The main topic: if A0*x + b0*y can divide n, to find out more than a*x+b*y can also remove N, find all the B (0<=a,b<n)
Analysis: Conditional can know a*x+b*y = K * (a0*x + b0*y)% n ====> (k * A0)% n = A, (k * B0)% n = B, (K=[0....N)).
PS. Remember sort to repeat ...
The code is as follows:
==========================================================================================================
#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;Const intMAXN =10007;Const intOO = 1e9+7;structnode{intA, B;} ANS[MAXN];BOOLCMP (Node A, Node B) {if(A.A! =B.A)returnA.A <B.A; returnA.B <b.b;}intMain () {intI, N, A0, B0, k=1; scanf ("%d%d%d", &n, &A0, &B0); for(i=0; i<n; i++) {Ans[i]. A= (a0*i)%N; Ans[i]. B= (b0*i)%N; } sort (ans, ans+N, CMP); for(i=1; i<n; i++) { if(Ans[i]. A! = ans[i-1]. A | | Ans[i]. B! = ans[i-1]. B) Ans[k++] =Ans[i]; } printf ("%d\n", K); for(i=0; i<k; i++) printf ("%d%d\n", Ans[i]. A, Ans[i]. B); return 0;}
Magic PAIRS-SGU 119 (congruence)