Lightoj Aladdin and the Flying Carpet 1341 "arithmetic basic theorem + geometry"

Source: Internet
Author: User

1341-aladdin and the Flying Carpet
PDF (中文版) Statistics Forum
Time Limit: 3 second (s) Memory Limit: MB

It's said that Aladdin had to solve seven mysteries before getting the magical Lamp which summons a powerful Genie. Here we is concerned about the first mystery.

Aladdin was-about-to-enter to a magical-cave, led by the evil sorcerer who disguised himself as Aladdin ' s uncle, found a s Trange Magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there is a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped and not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.

Now all given the area of the carpet and the length of the minimum possible side of the carpet, your task was to find H OW many types of carpets is possible. For example, the area of the carpet, and the minimum possible side of the carpet are 2, then there can are both types of C Arpets and their sides are: {2, 6} and {3, 4}.

Input

Input starts with an integer T (≤4000), denoting the number of test cases.

Starts with a line containing-integers: a B (1≤b≤a≤1012) where a denotes the area of The carpet and b denotes the minimum possible side of the carpet.

Output

For each case, print the case number and the number of possible carpets.

Sample Input Output for Sample Input

2

10 2

12 2

Case 1:1

Case 2:2



Test instructions

To a pair of numbers a, a is a rectangular area, ask how many integers of the side of the combination can form an area of a rectangle, the minimum required edge must not be less than B.

Plainly, is the number of the approximate pairs of a within the interval [B, a]. The approximate pair is "4,5" "5,4" this is a pair. Salvation does not take order.

Problem Solving Ideas:

The basic theorem of arithmetic is mainly used to introduce some properties of the fundamental theorems:

(1) a positive integer greater than 1 N, if its standard decomposition is: , then it has a number of positive   . (2) The sum of all its positive factors is . when It is called N is the complete number. The existence of odd perfect numbers is a conjecture that has not been resolved so far. (3) The maximum common factor of integers A and B can be redefined by using the basic theorem of arithmetic and least common multiple , and prove . (4) In addition, it can be proved that the square root 2 is irrational number and so on. (5) The number of proofs is infinite. The main problem is to find the number of positive factors num, after the NUM/2, and then in the enumeration 1-b belong to a positive factor of the number CNT, with NUM-CNT is our final result.

Be careful when dealing with positive factors. Also, when NUM is in addition to 2, we think that num is an odd number when the direct addition of 2 will be wrong? In fact, only when there is an approximate shape of the edge is a square, num that must be an odd number, direct/2 minus the square of the case.

AC Code:

#include <stdio.h> #include <math.h> #include <vector> #include <queue> #include <string> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm>using    namespace Std;const int maxn = 1000000;int prime[maxn];int is_prime[maxn];int tot;typedef Long Long ll;void find_prime () {    tot=0;    Is_prime[1]=1;            for (int i=2;i<maxn;i++) {if (!is_prime[i]) {prime[tot++]=i;        for (int j=i*2;j<maxn;j+=i) is_prime[j]=1;    }}}ll Solve (ll N) {ll ans=1;        for (int i=0;i<tot&&n;i++) {LL num=0; if (prime[i]>n) break;         Do not add this time-out ah ...            while (n%prime[i]==0) {n/=prime[i];        num++;    } ans*= (1+num);     } if (n>1) ans*= (+); return ans;}    int main () {find_prime ();    LL s,b;    int t;    scanf ("%d", &t);    int xp=1;        while (t--) {scanf ("%lld%lld", &s,&b); if (b*b>=s) {printf ("Case%d:0\n", XP++); Continue;}        LL Num=solve (s);        num/=2;        for (LL i=1;i<b;i++) if (s%i==0) num--;    printf ("Case%d:%lld\n", xp++,num); } return 0;}


Copyright NOTICE: This article is the original blogger articles, reproduced please indicate the source.

Lightoj Aladdin and the Flying Carpet 1341 "arithmetic basic theorem + geometry"

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.