Uva294divisors (unique decomposition theorem + approximately several numbers)

Source: Internet
Author: User

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)

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.