Topic Links:
Https://www.hackerrank.com/contests/w26/challenges/pairs-again topic:
Given a number n, ask how many to a, a, a, a, a, xa+by=n xa+by=n have at least one solution, a<b A and 0<b,0<y 0, and X, Y, and X, s are integers. Problem Solving Process:
Game time, the original game luck is good, the problem saw a bunch of people WA more than 60, so did not dare to do, and then to fill up, but also to learn how to preprocess approximate. Topic Analysis:
The time limit of this problem is very strange, can run to 59 seconds.
All the approximate numbers of the first n are preprocessed here. Then enumerate A and x x, N−xa n-xa BX BX, the BX bx as b b, recording the BX BX more than a a, but for ax+by=cx+by=n ax+by = cx + by = n situation to go to a heavy.
The pretreatment of the approximate method can be compared with the idea of Euler sieve. AC Code:
#include <bits/stdc++.h> using namespace std;
const int MAX = 312345;
Vector<int> Divisor[max];
int Flag[max];
int main () {int n;
CIN >> N; Approximate number of pre-preprocessing N, analogy Euler sieve method for (int i = 2; i < n; i++) {for (int j = i; J < n; j + = i) {divisor[j
].push_back (i);
}} int ans = 0;
memset (flag, 0, sizeof (flag));
for (int a = 1, a < n; a++) {for (int xa = A; xa < n; xa + = a) {int yb = N-XA;
for (int i = 0; i < divisor[yb].size (); i++) {int t = Divisor[yb][i];
Let each t be used once for each a, and ensure T > a if (flag[t] = = A | | t <= a) continue;
Flag[t] = A;
ans++;
}}} cout << ans; }