2017多校-3

这次一看好多数学公式就知道又要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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值