【bzoj1408】 Noi2002—Robot
http://www.lydsy.com/JudgeOnline/problem.php?id=1408 (题目链接)
题意
定义了3种数,分别求这3种数的φ的和,其中φ(1)=0。
Solution
原来还有这种公式,n的因数的φ的和等于n。。$${\sum_{d|n}φ(d)=n}$$
完了思维僵化了。。
http://blog.csdn.net/lych_cys/article/details/50278169
细节
代码
// bzoj1408 #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #define LL long long #define inf 2147483640 #define MOD 10000 #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; const int maxn=1010; int f[maxn][2],p[maxn]; int n,m; int power(int a,int b) { int res=1; while (b) { if (b&1) res=res*a%MOD; a=a*a%MOD;b>>=1; } return res; } int main() { scanf("%d",&n);m=1; for (int x,y,i=1;i<=n;i++) { scanf("%d%d",&x,&y); m=m*power(x,y)%MOD; if (x!=2) p[++p[0]]=x; } m--;f[1][0]=1;f[1][1]=p[1]-1; for (int i=2;i<=p[0];i++) { f[i][0]=(f[i-1][1]*(p[i]-1)+f[i-1][0])%MOD; f[i][1]=(f[i-1][0]*(p[i]-1)+f[i-1][1])%MOD; } f[p[0]][0]--; printf("%d\n",(MOD+f[p[0]][0])%MOD); printf("%d\n",(MOD+f[p[0]][1])%MOD); printf("%d\n",(2*MOD+m-f[p[0]][1]-f[p[0]][0])%MOD); return 0; }
This passage is made by MashiroSky.