hdu-5524 Product

Source: Internet
Author: User

Test instructions


n<=100000,ai<=100000;

Because the answer can be very large, so long as the output modulus 1000000007 after the value can be;

Multiple sets of data, N and <=500000; of all data


Exercises

Very interesting a number of number problems, although the game is not launched to abandon the treatment;

First of all, because the quality of n is in the range of N, so we can preprocess some prime, such as the minimum factor of things;

And then we got n=p1^t1*p2^t2*p3^t3...pk^tk this form of n;

To calculate the approximate product, we consider a separate calculation for each prime number;

N A total of (t1+1) * (t2+1) *...* (tk+1) so many approximations;

For a mass factor pi, the Pi^0,pi^1,pi^2...,pi^ti values may appear in each approximate number, with ti+1 species;

And the chances of their appearing are the same, so that each pi^j has a π (tx+1)/(ti+1) time;

Intuitively, in fact, we use all the other mass factors of N to make up all the numbers that can be gathered, and then use Pi^0,pi^1,pi^2...,pi^ti to multiply them to get a tx+1 of π.

Then pi in the approximate product of a total of (0+1+2+3+...+ti) * π (tx+1)/(ti+1) times, after the enumeration of Pi fast power calculation can be;

However, there are some details, such as the obvious Pi index will explode, then use the Fermat theorem mod 1000000007-1 can be;

And after the MoD except (ti+1) bad processing, then processing prefix product and suffix product;

As for the previous arithmetic progression summation of the addition of two, in the limit data ti happens to explode the int some, but open long long and then discuss the odd even can be done;

The last point, if you are tle, be careful with the many sets of data from the pit daddy! Complexity may be incorrect in multiple sets of data;


Code:


#include <stdio.h> #include <string.h> #include <algorithm> #define N 110000#define MoD 1000000007using namespace Std;typedef Long long ll;int pri[n],fp[n],tot;ll q[n];int sl[n],sr[n];bool vis[n];void Init (    int n) {int i,j;    tot=0;    memset (vis,0,sizeof (vis[0)) * (n+1));    memset (q,0,sizeof (q[0)) * (n+1));        for (i=2;i<=n;i++) {if (!vis[i]) Pri[++tot]=i,fp[i]=tot;            for (j=1;j<=tot&&pri[j]*i<=n;j++) {vis[pri[j]*i]=1;            Fp[pri[j]*i]=j;        if (i%pri[j]==0) break;    }}}int pow (int x,int y) {if (y<0) while (1) puts ("fuck");    int ret=1;        while (y) {if (y&1) ret= (LL) Ret*x%mod;        x= (ll) X*x%mod;    y>>=1; } return ret;}    int main () {int n,i,x,y,ans;        while (scanf ("%d", &n)!=eof) {init (n);            for (i=1;i<=n;i++) {scanf ("%d", &y);            if (!y) continue;          X=i;  while (x!=1) {q[fp[x]]+=y;            X/=PRI[FP[X]];        }} sl[0]=sr[tot+1]=1;        for (i=1;i<=tot;i++) {sl[i]=sl[i-1]* (q[i]+1)% (mod-1);        } for (i=tot;i>=1;i--) {sr[i]=sr[i+1]* (q[i]+1)% (mod-1); } for (i=1,ans=1;i<=tot;i++) {y= (q[i]&1?) ( q[i]+1)/2% (mod-1) * (q[i]% (mod-1)): q[i]/2% (mod-1) * ((q[i]+1)% (mod-1)))% (mod-1) * ((LL) sl[i-1]*sr[i+1]% (mod-1))% (            MOD-1);        ans= (LL) Ans*pow (pri[i],y)%mod;    } printf ("%d\n", ans); } return 0;}



hdu-5524 Product

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.