B axb (simplified version)
Time Limit:233ms Memory limit:65535k
Question types: programming language: Unlimited
Describe
Give two Series A, b, construct a matrix mat, make mat[i][j] = a[i] * B[j]. Find out how many different values are in the mat.
Input format
Enter T to indicate that there is a T set of test data: For each set of test data, enter a row of 9 integers n, m, A0, B0, P, q, x, Y, mx. where a[0] = a0,a[i] = a[i-1] * p + x (1 <= i < n); b[0] = B0, b[j] = b[j-1] * q + y (1 <= J < m). Because the generated numbers are larger, each element of A and B is modeled MX for each one. Data range: T <= wuyi <= N, M <= 20001 <= a0, B0, P, q, x, y, mx <= 1000
Output format
One row per group of data, output the corresponding results.
Input sample
12 2 1 2 3 4 5 7 10
Output sample
4
Hint
Explanation sample:a[] = {1, 8};b[] = {2, 5};mat[][] = { {2, +}, {5, 40}};
#include <stdio.h>#include<string.h>inta[ -],b[ -],cc[4000000];intMain () {intt,t; scanf ("%d",&T); intNum[t]; for(t=0; t<t;t++) {Num[t]=0; inti,j; intn,m,a0,b0,p,q,x,y,mx; scanf ("%d%d%d%d%d%d%d%d%d",&n,&m,&a0,&b0,&p,&q,&x,&y,&MX); a[0]=a0%MX; b[0]=b0%MX; for(i=1; i<n;i++) A[i]= (a[i-1]*P+X)%MX; for(i=1; i<m;i++) B[i]= (b[i-1]*q+y)%MX; intC=0; Memset (CC,0,sizeofcc); for(i=0; i<n;i++) for(j=0; j<m;j++) {C=a[i]*B[j]; if(!cc[c] \ \ Calculate the number of non-overlapping {cc[c]++; Num[t]++;} } } for(t=0; t<t;t++) printf ("%d\n", num[t]); return 0;}
Question 1 Simplified version