21: Maximum prime factor sequence, 21-factor sequence

Source: Internet
Author: User

21: Maximum prime factor sequence, 21-factor sequence
21: maximum quality factor sequence

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Input two positive integers m, n (1 <m <n <= 5000), and output the maximum prime factor (including m and n) of each number from m to n in sequence; if a certain number is a prime number, the output is itself ).

Input
A row contains two positive integers m and n separated by a single space.
Output
The maximum quality factor of each integer in one row, separated by commas.
Sample Input
5 10
Sample output
5,3,7,2,3,5
Source
Yuan Pei-From Whf
 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 int vis[10001]; 6 int main() 7 { 8     int m,n; 9     cin>>m>>n;10     for(int i=2;i<=sqrt(n+0.5);i++)11     {12         if(vis[i]==0)13         {14             for(int j=i*i;j<=n;j=j+i)15             {16                 vis[j]=1;17             }18         }19     }20     int flag=0;21     for(int i=m;i<=n;i++)22     {23         if(vis[i]==0&&flag==1)24         {25             cout<<","<<i;26         }27         else if(vis[i]==0&&flag==0)28         {29             cout<<i;30             flag=1;31         }32         else33         {34             for(int j=i-1;j>=2;j--)35             {36                 if(i%j==0&&vis[j]==0)37                 {38                     if(flag==1)39                     cout<<","<<j;40                     else 41                     {42                         cout<<j;43                         flag=1;44                     }45                     break;46                 }47                 48             }49         }50     }51     return 0;52 }

 

Related Article

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.