Robot m number

Source: Internet
Author: User
Description

In 3030, Macsy was deploying a batch of robots on Mars. In the 1th second, he shipped robot 1th to Mars, and robot 1th could make other robots. In the 2nd second, robot number 1th made the first robot, robot number 2nd. In the 3rd second, Robot 1th made another robot, robot number 3rd. Every second, robot 1th can create a new robot. The number of robots made in M seconds is M. We can call it the robot m, or the M-number robot. After the robot was created, it began to work immediately. M robot will take a break every m seconds. For example, the number 3rd robot will be in section 6,9,12, ... Seconds, while the rest of the time is working. When the robot breaks, its memory will be transplanted into the brain of the then-born robot. For example, when the number 6th robot was born, the 2,3 robot was resting, so the number 6th robot would receive a copy of the 2nd and 3rd robot's memory. We call 2nd, Robot number 3rd is the teacher of robot number 6th. If two robots do not have a mentor relationship and do not have a common teacher, they are said to be independent of the knowledge of the two robots. Note: Robot number 1th is independent of all other robots (because only the number 1th will build the robot), and it is not a teacher of any robot. The independent number of a robot is the number of robots whose numbers are smaller and independent of its knowledge. For example, 1th robot independent number of 0, 2nd robot Independent number of 1 (1th robot and its knowledge independent), 6th robot Independent number 2 (1,5 robot and its knowledge independent, 2,3 robot is its teacher, and 4th robot and it has a common teacher--2 robot). The newly created robot has 3 different occupations. For a robot numbered m, if the M can be decomposed into an even number of different odd primes, then it is a politician, for example, number 15; otherwise, if M itself is an odd prime or can break m into an odd number of different odd primes, it is a soldier, for example, number 3, number 165. Other numbered robots are academics, such as number 2, number 6, number 9. The robot M, which was born in M seconds, wants to know the sum of the independent numbers of all the politicians, the sum of the independent numbers of all the soldiers, and the sum of the independent numbers of all the scholars in it and its teachers. But the robot m is busy with work and no time to calculate, can you help it. To facilitate your calculations, MACSY has helped you to do the M factor decomposition. For ease of output, only the remainder of the output sum divided by 10000 is required.

Input

The first line of the input file is a positive integer k (1<=k<=1000), and K is the number of different element factors for M. The following k lines, two integers per line, pi, ei, represent the I-factor of M and its exponent (i = 1, 2, ..., K). P1, p2, ..., PK is a different prime number. All vegetarian factors are arranged according to small to large, i.e. P1 analysis

First analysis test instructions, do not be the topic to halo, First, "a number of knowledge independent number" refers to the number of M coprime. Secondly, "X is a teacher of xxx" actually refers to X is a certain approximate. So we can get a better understanding of the test instructions of this problem.
And then we ask for the Euler function that is the approximate of M and satisfies the conditions of the problem.
So we set the DP equation for this:
f[i,j]=f[i,j]+f[i-1,j]+f[i-1,j-1]* (p[i]-1)
Then the classification according to the topic conditions can be.
Then there is a point, which is the most critical question: How to seek the sum of the independent number of scholars.
first of all, we only know the number of Euler functions of all m, and that is actually m.
How to prove it. Here's a way to:
We set the number of ansi-1 for the current i-1 of prime numbers.
Then category discussion: ANSI
1. Choose Pi Separately, then it is
(p−1) + (p−1) p+ (p−1) p2+ (p−1) P3: (p−1) ppe−1 (p-1) + (p-1) p+ (p-1) p^2+ (p-1) P^3: (p-1) P^{pe-1}
2. Do not choose Pi, then it is ansi-1
3. The preceding number and pi combination:
Ans (p−1) +ans (p−1) P+ans (p−1) P2+ans (p−1) P3: Ans (p−1) ppe−1 ans (p-1) +ans (p-1) P+ans (p-1) P^2+ans (p-1) P^3..ans (p-1) p^{pe-1}

So ans can be launched (ans+1) (p−1) (p+. +pe−1) (ans+1) (p-1) (p+.. +P^{E-1})
Then we can use the geometric series summation formula to get Ans-> (ans+1) * (p^{e+1}-p)
from the last generation, ANS can be launched ansi=p1e1∗. Piei ansi=p1^{e1}*. Pi^{ei}
This gives you the sum of the Euler functions of all the M's approximations is M. The
has solved the problem very well.

 #include <iostream> #include <cstdio> #include <algorithm> #include <
cstdlib> #include <cmath> #include <cstring> using namespace std;
const int n=1005;
const int mo=10000;
int n,p[n],e[n],f[n],ans,fir,sec;
    int msort (int x,int y) {int d=1,c=x;
        while (y) {if (y&1) d= (d*c)%mo;
        C= (c*c)%mo;
    y=y>>1;
} return D;
    } int main () {scanf ("%d", &n);
    for (int i=1;i<=n;i++) scanf ("%d%d\n", &p[i],&e[i]);
    F[0]=1;int a=1;
    if (p[1]==2) a=2;
    for (int i=a;i<=n;i++) for (int j=i-a+1;j;j--) f[j]= (f[j]+f[j-1]* (p[i]-1))%mo;
    for (int i=1;i<=n;i++) if (i%2) fir= (Fir+f[i])%mo;else sec= (sec+f[i])%mo;
    Ans=1;
    for (int i=1;i<=n;i++) ans= (Ans*msort (P[i],e[i]))%mo;
    printf ("%d\n%d\n%d\n", Sec,fir, (Ans-fir-sec-1+mo+mo)%mo);
Fclose (stdin); }

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.