Created
February 5, 2011 21:58
-
-
Save clholgat/812839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
void genseq(int *a, int N, int P); | |
void numPairs(int *a, int *b, int P, int L); | |
int pairs = 0; | |
int M = 0; | |
int N = 0; | |
int main(int argv, char *argc[]){ | |
FILE *fp = fopen(argc[1], "r"); | |
int numtrial = 0; | |
int P = 0; | |
int L = 0; | |
int A1 = 0; | |
int A2 = 0; | |
int A3 = 0; | |
int A4 = 0; | |
int A5 = 0; | |
int *A = NULL; | |
int B1 = 0; | |
int B2 = 0; | |
int B3 = 0; | |
int B4 = 0; | |
int B5 = 0; | |
int *B = NULL; | |
fscanf(fp, "%d", &numtrial); | |
for(int i = 0; i < numtrial; i++){ | |
fscanf(fp, "%d %d", &P, &L); | |
fscanf(fp, "%d %d %d %d %d %d", &N, &A1, &A2, &A3, &A4, &A5); | |
A = (int *)malloc(sizeof(int)*(N>5?N:5)); | |
A[0] = A1; | |
A[1] = A2; | |
A[2] = A3; | |
A[3] = A4; | |
A[4] = A5; | |
if( N > 5){ | |
genseq( A, N, P); | |
} | |
fscanf(fp, "%d %d %d %d %d %d", &M, &B1, &B2, &B3, &B4, &B5); | |
B = (int *)malloc(sizeof(int)*(M>5?M:5)); | |
B[0] = B1; | |
B[1] = B2; | |
B[2] = B3; | |
B[3] = B4; | |
B[4] = B5; | |
if(M > 5){ | |
genseq(B, M, P); | |
} | |
numPairs(A, B, P, L); | |
printf("%d\n", pairs); | |
free(A); | |
A = NULL; | |
free(B); | |
B = NULL; | |
} | |
} | |
void genseq(int *A, int N, int P){ | |
//int A2 = A[3]; | |
//int A1 = A[4]; | |
for(int i = 5; i < N; i++){ | |
A[i] = (A[i-2]*A[2]+A[i-1]*A[3]+A[4])%P; | |
} | |
} | |
void numPairs(int *A, int *B, int P, int L){ | |
pairs = 0; | |
for(int i = 0; i < N; i++){ | |
/*if(A[i] == 0){ | |
pairs += M; | |
printf("I is %d\n", i); | |
continue; | |
}*/ | |
for(int j = 0; j < M; j++){ | |
//printf("inner loop\n"); | |
/*if(B[j] == 0){ | |
pairs += 1; | |
}else*/ if(((A[i]*B[j]) % P) < L){ | |
printf("I %d J %d\n", i, j); | |
pairs += 1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment