1341-aladdin and the Flying Carpet---light oj (unique decomposition theorem + prime number screening)

Source: Internet
Author: User

http://lightoj.com/volume_showproblem.php?problem=1341

The main topic: give you the area of the rectangle (the rectangle's side length are positive integers), let you find the smallest side is greater than the number of rectangles equal to B.

What is the unique decomposition theorem: The basic theorem of arithmetic can be expressed as: any one natural number greater than 1 N, if n is not prime , then n can be uniquely decomposed into a finite number of primes of the product N=p1a1p2a2p3A3 ... PnAn, where p1<p2<p3......<pn are prime, where the exponential AI is a positive integer. Such decomposition is called the standard decomposition of N

After we have found the number of factors of n, we divide by 2, get the number of factors in half, and then loop from the beginning to the B unqualified directly minus

#include <stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespacestd;#defineN 1001000#defineESP 1e-8#defineINF 0x3f3f3f3f#defineMemset (A, B) memset (A,b,sizeof (a))intPrime[n], K, vis[n];voidPrime () {k=0; memset (Vis,0);  for(intI=2; i<n; i++)    {        if(!Vis[i]) {Prime[k++] =i;  for(intJ=i+i; j<n; j+=i) vis[j]=1; }    }}///Prime number ScreeningLong LongSolveLong LongN) {    Long Long intsum =1;  for(intI=0; I<k && prime[i]*prime[i]<=n; i++)    {        if(N%prime[i] = =0)        {            intans=0;  while(N%prime[i] = =0) {ans++; N/=Prime[i]; } Sum*= (1+ans); }    }    if(n>1) Sum*=2; returnsum;}///to find the number of n factors;intMain () {intT, t=1; scanf ("%d", &T);    Prime ();  while(T--)    {        Long Longb; scanf ("%lld%lld", &a, &b); if(A <= b*b) {printf ("Case %d:0\n", t++); Continue; }        Long Long intnum =solve (a); Num/=2;  for(intI=1; i<b; i++)        {            if(a% i = =0) Num--; } printf ("Case %d:%lld\n", t++, num); }    return 0;}

1341-aladdin and the Flying Carpet---light oj (unique decomposition theorem + prime number screening)

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.