Question 1 Simplified version

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.