这次一看好多数学公式就知道又要GG了,只写了一道特别水的题。1008一直在纠结莫比乌斯函数,最后看了题解发现真坑。
RXD’s date
http://acm.hdu.edu.cn/showproblem.php?pid=6066
超级水,求出一组数中小于等于35的个数
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n;
int a[1010];
while(scanf("%d",&n)!=EOF)
{
int s=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<=35)
{
s++;
}
}
printf("%d\n",s);
}
return 0;
}
RXD and math
http://acm.hdu.edu.cn/showproblem.php?pid=6063
计算出前几个就能看出规律了
n^k=2时所求值=2;
n^k=3时所求值=3;
n^k=4时所求值=4;
n^k=5时所求值=5;
……
n^k时所求值n^k;
就是快速幂求n^k。
官方题解:注意到一个数字x必然会被唯一表示成a^2×b的形式.其中∣μ(b)∣=1。 所以这个式子会把[1, n^k]
的每个整数恰好算一次. 所以答案就是n^k。快速幂即可. 时间复杂度O(logk)..
#include <iostream>
#include <cstdio>
#include <cmath>
#define LL long long
#define MOD 1000000007
using namespace std;
LL poww(LL a,LL i,LL n)
{
if(i==0)return 1%n;
LL temp=poww(a,i>>1,n);
temp=((temp%n)*(temp%n))%n;
if(i&1)
{
temp=((temp%n)*(a%n))%n;
}
return temp%n;
}
int main()
{
int cas=1;
LL n,k;
while(cin>>n>>k)
{
LL sum=poww(n,k,MOD);
cout<<"Case #"<<cas++<<": "<<sum<<endl;
}
return 0;
}