码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1408: [Noi2002]Robot

时间:2016-12-24 11:24:21      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:void   ble   line   names   ica   namespace   max   mem   pac   

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\n%d\n%d\n",ans1,ans2,ans3);
39     return 0;
40 }//Cap ou pas cap. Cap.
View Code

By NeighThorn

BZOJ 1408: [Noi2002]Robot

标签:void   ble   line   names   ica   namespace   max   mem   pac   

原文地址:http://www.cnblogs.com/neighthorn/p/6216829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!