Codevs 2964 Common Prime factor

Source: Internet
Author: User

2964 Common Prime factor

time limit: 1 sspace limit: 32000 KBtitle level: Silver SolvingTitle Description Description

The small single classmate just learned a number decomposition into several prime (also called prime number) factor multiplication knowledge.

Example: 12=2*2*3;25=5*5;144=2*2*2*2*3*3 And so on, for example, the first expression, which shows that the integer 12 can decompose 2, 2, 3 of these three prime number factors. The teacher gave him a homework, small single seems to see, how will not do, had to humbly ask you classmates (he went to bed!) )

The problem is this: there are two positive integers, a, a, a, and a, B, and a few of the same vegetarian (qualitative) factors. Please output the number. For example: 12 and 144 the same vegetarian (qualitative) factor is 2,2,3; Output 3. 12 and 25 have the same element (qualitative) factor, then output 0.

Enter a description Input Description

The first row two numbers: A, b, separated by a space in the middle.

Output description Output Description

An integer that represents the same number of vegetarian (qualitative) factors as a and B.

Sample input Sample Input

12 144

Sample output Sample Output

3

Data range and Tips Data Size & Hint

For 50% of data, ensure 2≤a,b≤100

For 100% of data, ensure 2≤a,b≤10000

Syq proposition.

#include <iostream>#include<cmath>#include<cstring>#include<cstdio>using namespacestd;intb;inta1[10001],b1[10001];intans=0;intp1,p2;BOOLs1[10001],s2[10001];intShaiintX//determine if it is a prime number{    if(x==2)return 1;  for(intI=2; i<=sqrt (x); i++)      if(x%i==0)return 0;}intMain () {CIN>>a>>b;  for(intI=2; i<=a;i++)    {        if(a==1) Break;//no contribution to the answer after 1 (mod not)         while(a%i==0)      {          if(Shai (i)) a1[++p1]=i,a/=i;//      }    }           for(intI=2; i<=b;i++)    {        if(b==1) Break;  while(b%i==0)      {          if(Shai (i)) b1[++p2]=i,b/=i; }    }     for(intI=1; i<=p1;i++)       for(intj=1; j<=p2;j++)        if(A1[i]==b1[j]&&!s1[i]&&!s2[j])//sentence weight{S1[i]=1; S2[J]=1; Ans++; } printf ("%d", ans); return 0;}

Codevs 2964 Common Prime factor

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.