Group Competition 23-A (number theory) E (HEAP)

Source: Internet
Author: User

Question A is hard to understand. The number of quality factors that output the product of 10 numbers not greater than 100000

A large number is not allowed. The time is 2 S. X. First, we will learn the knowledge of a number theory:

Positive number N can be decomposed into P1 ^ A1 * P2 * A2 *...... * PK ^ AK

Pi is a pair of different prime numbers, and AI is the corresponding exponent. Because of N factors, you can select 0 and 1 ..... N is selected in n + 1. Then the approximate number of N is (1 + A1) * (1 + A2 )*.....

#include<iostream>#include<cmath>#include<algorithm>using namespace std;int a[10001];int main(){int i,j,n,re;for(i=1;i<=10;i++){scanf("%d",&n);for(j=2;;j++){while(n%j==0&&n!=1){a[j]++;n/=j;}if(n==1)break;}}re=1;for(i=2;i<=10000;i++){if(a[i]!=0){re=re*(a[i]+1);}}printf("%d\n",re%10);return 0;}

E:

The practice is heap. I would like to give up. Thanks to mango's reminder, I remember that there is such a good thing as priority_queue in STL, which has grown C ++'s power. Note that you only need to maintain half the length, otherwise the memory will still be stuck.

#include<iostream>#include<string>#include<cstdio>#include<queue>using namespace std;priority_queue<int>a;int main(){int N;double f;int x,mid,mid1,mid2,TT;int i;while(~scanf("%d",&N)){while(!a.empty ())a.pop();for(i=0;i<N;i++){scanf("%d",&x);a.push(x);//TT=a.top();//int len=a.size();if(a.size ()>N/2+1) a.pop();}if(N%2==0) {mid1=a.top();a.pop();mid2=a.top();a.pop();f=((double)mid1+(double)mid2)/2;printf("%.1lf\n",f);}else {mid=a.top();printf("%d.0\n",mid);}}return 0;}

Cherish the opportunity of each competition. Come on, I am really ashamed to see other acmers working so hard.

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.