Topic links
Test instructions: Enter two integers l,u (L <= U <= 1000000000, u-l <= 10000), the number of integers in the statistic interval "L,u" which is the most positive, the one with the least number of outputs
I was thinking of using Euler functions to make a table for all the approximate numbers, but you are too large to solve the direct violence
By using the unique decomposition theorem, the prime number of the square root 1000000000 is selected and the L,u interval is decomposed.
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 Const intMax =34000;7 intPrime[max +5],total,flag[max];8 voidget_prime ()9 {TenTotal =0; One for(inti =2; I <= Max; i++) A { - if(Flag[i] = =0) - { thePrime[++total] =i; - for(intj = i; J <= max/i; J + +) - { -Flag[i * j] =1; + } - } + } A } at intGET_GCD (intN) - { - intnum =0, ans =1; - for(inti =1; I <= total; i++) - { - if(Prime[i] >N) in Break; - if(n% prime[i] = =0) to { +num =0; - while(n% prime[i] = =0) the { *num++; $n = n/Prime[i];Panax Notoginseng } -Ans *= (num +1); the } + } A if(N >1) the { +Ans *=2; - } $ returnans; $ } - intMain () - { the intl,u,test; - get_prime ();Wuyiscanf"%d", &test); the while(test--) - { Wuscanf"%d%d", &l, &u); - inttemp; About intMAXN =0, p; $ for(inti = l; I <= u; i++) - { -temp =GET_GCD (i); - if(Temp >MAXN) A { +MAXN =temp; thep =i; - } $ } theprintf"between%d and%d,%d has a maximum of%d divisors.\n", L, U, p, MAXN); the } the return 0; the}
View Code
Uva294divisors (unique decomposition theorem + approximately several numbers)