CSU 1803 2016 (congruence formula) 2016 Hunan Province 12th session of college students computer Program design Competition

Source: Internet
Author: User

Test Instructions
given positive integers n and m, count the number of positive integer pairs (A, b) that meet the following conditions:
1.1≤a≤n, 1≤b≤m;
2. AXB is a multiple of 2016.

Sample Input
About
to
1000000000 1000000000

Sample Output
1
30576
7523146895502644

Ideas
can be obtained by the congruence formula
A * b = (a) * (b)%
so if X*y is a multiple of 2016, then (2016*k + x) *y is also
It is only necessary to count the number of occurrences of the remainder of each modulo 2016 of the 1-n to reduce the number of cycles in the enumeration to 2016*2016.

1#include <cstdio>2typedefLong Long intLL;3 Const intN = .;4 intA[n], b[n];5 LL ans;6 intMainvoid)7 {8     intN, M, NX, MX;9      while(~SCANF ("%d%d", &n, &m))Ten     { OneNX = N/N; Amx = m/N; -          for(intI=0; i<n; ++i) -A[i] = NX, b[i] =MX; theNX = n%N; -mx = m%N; -          for(intI=1; i<=nx; ++a[i++]); -          for(intI=1; i<=mx; ++b[i++]); +Ans =0; -          for(intI=0; i<n; ++i) +              for(intj=0; j<n; ++j) A                 if(i*j%n = =0) atAns + = (LL) a[i] *B[j]; -printf"%lld\n", ans); -     } -     return 0; -}

CSU 1803 2016 (congruence formula) 2016 Hunan Province 12th session of college students computer Program design Competition

Related Article

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.