Ural 1355. Bald spot Revisited (number theory)

Source: Internet
Author: User

Question Link

A student dreamed of walking in a street with many bars. He can have a drink at each bar. All bars have a positive integer number. This person can go from bar n to the bar where the number can be divided by N. Now he wants to go from bar a to bar B. How much wine can he have at most.

Idea: Because B must be a multiple of A, which is multiplied by a from the beginning. In fact, it is to find the prime division that constitutes B/, the number of prime numbers that you can drink.

1 # include <stdio. h> 2 # include <string. h> 3 # include <iostream> 4 5 using namespace STD; 6 7 int sumnum (int n) 8 {9 for (INT I = 2; I * I <= N; I ++) // The Prime Number 10 {11 if (N % I = 0) {// if it is 0, one more, then, find 12 return 1 + sumnum (N/I); 13} 14} 15 return 0; 16} 17 int main () 18 {19 int T; 20 scanf ("% d", & T); 21 int A, B; 22 while (t --) 23 {24 scanf ("% d", &, & B); 25 if (B %! = 0) 26 {27 printf ("0 \ n"); 28 continue; 29} 30 else if (a = B) 31 {32 printf ("1 \ n"); 33 continue; 34} 35 int ans = sumnum (B/A); 36 printf ("% d \ n ", ans + 2); // Add a and B37} 38 return 0; 39}
View code

 

Ural 1355. Bald spot Revisited (number theory)

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.