Test instructions: Give you a positive integer n, ask how many positive integers you exist on a, B (a<b), satisfy the condition: there is a positive integer x, y, which makes ax+by=n.
The approximate number of all the numbers within N is preprocessed, then the violent enumeration A, the violent enumeration of X, and then enumerates all the n-ax, the sentence weight, the statistical answer can be.
#include <cstdio> #include <vector> #include <algorithm>using namespace Std;typedef vector<int >::iterator iter;vector<int>divisors[300010];int n,used[300010],ans;bool cmp (const int &A,CONST int &B) {return a>b;} int main () {scanf ("%d", &n), for (int. i=1;i<=n;++i) {for (int j=1;j*j<=i;++j) if (i%j==0) { Divisors[i].push_back (j); if (j*j!=i) divisors[i].push_back (i/j); } Sort (Divisors[i].begin (), Divisors[i].end (), CMP); } for (int a=1;a<n;++a)//enumeration A for (int x=1;x*a<n;++x)//enum x{ int yb=n-x*a; For (ITER It=divisors[yb].begin (); It!=divisors[yb].end (); ++it)//*it is b { if ((*it) <=a)//Because B>a Break ; if (used[*it]!=a)//Prevent duplicate statistics { ++ans; Used[*it]=a;}}} printf ("%d\n", ans); return 0;}
"Enumeration approximate" Hackerrank-week of Code 26-satisfactory Pairs