Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5666
Test instructions: There is a line x+y=n, to find the line and the axis of the triangle enclosed by how many integer points, not on the axis and line, so that the result of the P-remainder
The obvious answer is (1+2+3+...+a-2)%P = ((A-1) (a-2)/2)%P;
Because the range of a and p are relatively large, the direct multiplication will explode ll's, so you can use the idea of a fast power matrix;
X*y = 2*X*Y/2; Y is an even number;
X*y = x + 2*x*y/2; Y is odd;
So there's a bit of code:
#include <iostream> #include <vector> #include <stdio.h> #include <string.h> #include < stdlib.h> #include <algorithm> #include <math.h>using namespace std; #define N 1050#define PI 4*atan (1) # Define met (A, b) memset (A, B, sizeof (a)) typedef long Long LL; ll Mul (ll X, ll y, ll Mod) { if (y = = 0) return 0; LL ans = 2 * Mul (x, Y/2, Mod)%mod; if (y%2) ans = (ans+x)%mod; return ans;} int main () { int T; scanf ("%d", &t); while (t--) { LL ans, p, q, N, mod; scanf ("%i64d%i64d", &n, &mod); p = n-1; Q = n-2; if (p&1) ans = Mul (p, Q/2, mod); else ans = Mul (P/2, q, mod); printf ("%i64d\n", ans); } return 0;}
Segment---hdu5666 (two long long to find remainder of long long)