zoukankan      html  css  js  c++  java
  • BZOJ 1408: [Noi2002]Robot

    1408: [Noi2002]Robot

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 510  Solved: 344
    [Submit][Status][Discuss]

    Description

    Input

    Output

    Sample Input

    3
    2 1
    3 2
    5 1

    Sample Output

    8
    6
    75

    HINT

    90号机器人有10个老师,加上它自己共11个。其中政客只有15号;军人有3号和5号;学者有8个,它们的编号分别是:2,6,9,10,18,30,45,90。

    Source

    分析:

    这道题读完题就胜利了...TAT...

    其实就是用优(z)美(z)的语言描述了φ函数和μ函数...

    需要注意的是φ(1)=0,数互异素数个数的时候不能数2...

    ans1和ans2都很好求,因为φ是积性函数,所以我们可以O(n)滴求出...ans3肿么求QAQ...我思考了好久发现自己是zz...所有数的φ之和不就是m么...

    减一减就好了...

    代码:

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 //by NeighThorn
     6 using namespace std;
     7 //大鹏一日同风起,扶摇直上九万里 
     8 
     9 const int maxn=1000+5,Mod=10000;
    10 
    11 int n,beg,end,ans1,ans2,ans3,p[maxn],e[maxn];
    12 
    13 inline int power(int x,int y){
    14     int res=1;
    15     while(y){
    16         if(y&1)
    17             res=res*x%Mod;
    18         (x*=x)%=Mod,y>>=1;
    19     }
    20     return res;
    21 }
    22 
    23 signed main(void){
    24     scanf("%d",&n);beg=1,end=n;
    25     for(int i=1;i<=n;i++)
    26         scanf("%d%d",&p[i],&e[i]);
    27     if(p[1]==2)
    28         beg++;
    29     for(int i=beg;i<=end;i++){
    30         int tmp1=ans1,tmp2=ans2;
    31         (ans1+=tmp2*(p[i]-1)%Mod)%=Mod;
    32         (ans2+=(tmp1+1)*(p[i]-1)%Mod)%=Mod;
    33     }
    34     ans3=1;
    35     for(int i=1;i<=n;i++)
    36         (ans3*=power(p[i],e[i]))%=Mod;
    37     ans3=(((ans3-1+Mod)%Mod-ans1+Mod)%Mod-ans2+Mod)%Mod;
    38     printf("%d
    %d
    %d
    ",ans1,ans2,ans3);
    39     return 0;
    40 }//Cap ou pas cap. Cap.
    View Code

    By NeighThorn

  • 相关阅读:
    POJ 1953 World Cup Noise
    POJ 1995 Raising Modulo Numbers (快速幂取余)
    poj 1256 Anagram
    POJ 1218 THE DRUNK JAILER
    POJ 1316 Self Numbers
    POJ 1663 Number Steps
    POJ 1664 放苹果
    如何查看DIV被设置什么CSS样式
    独行DIV自适应宽度布局CSS实例与扩大应用范围
    python 从入门到精通教程一:[1]Hello,world!
  • 原文地址:https://www.cnblogs.com/neighthorn/p/6216829.html
Copyright © 2011-2022 走看看