• 2017 Multi-University Training Contest


    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6063

    题目意思:字面意思,给出n,k,算出这个式子的答案。

    思路:比赛的时候是打表找规律过了,赛后仔细研究一下数学上的具体做法,首先莫比乌斯函数,就是他后面给的那个式子μ(n)=(1)k(n=p1p2pk)   p1,p2,p3pk是互不相同的的素数。满足这个条件的n,μ^2(n)=1,否则μ^2(n)=0;从这个定义里面我们发现所有满足μ^2(n)=0的n值必定满足n=a^2*b,其中μ^2(b)=1。我们建立一个这样不等式a^2*b<=n;变形以后得到a<=sqrt(n/b)。很明显如果a取整数,那么a可以等于1,2,3,4,5……floor(sqrt(n/b)),共floor(sqrt(n/b))项,满足任何一项的的莫比乌斯函数等于0的。所以每一个莫比乌斯函数的平方等于1的数乘上floor(sqrt((n/i))),相当于把后面因为他被而变成0的项给补上了。所以相当于每一项的值都是1,所以这个式子的答案就是n,至于给n^k完全就是为了,让你推出这个公式以后,考一下你快速幂姿势。

    代码:

     1 //Author: xiaowuga
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <set>
     5 #include <vector>
     6 #include <queue>
     7 #include <cmath>
     8 #include <cstring>
     9 #include <cstdio>
    10 #include <ctime>
    11 #include <map>
    12 #include <bitset>
    13 #include <cctype>
    14 #define maxx INT_MAX
    15 #define minn INT_MIN
    16 #define inf 0x3f3f3f3f
    17 #define mem(s,ch) memset(s,ch,sizeof(s))
    18 #define nc cout<<"nc"<<endl
    19 const long long mod=1e9+7; 
    20 using namespace std;
    21 typedef long long LL;
    22 LL q_power(LL a,LL k){
    23     LL ans=1;
    24     a%=mod;
    25     while(k){
    26         if(k%2) ans=(ans*a%mod+mod)%mod;
    27         k/=2;
    28         a=(a*a%mod+mod)%mod;
    29     }
    30     return ans;
    31 }
    32 int main() {
    33     ios::sync_with_stdio(false);cin.tie(0);
    34     LL n,k,ca=0;
    35     while(cin>>n>>k){
    36         cout<<"Case #"<<++ca<<": "<<q_power(n,k)%mod<<endl;
    37     } 
    38     return 0;
    39 }
    View Code
  • 相关阅读:
    Python基础(三)
    Python基础(二)
    Python基础(一)
    Introduction of python
    加油,加油
    打不开Call Hierarchy和History的解决方法
    jdbc:oracle:thin:@localhost:1521:orcl和jdbc:oracle:thin:@localhost:1521/orcl的区别
    Java常见异常
    ArrayList和Array区别
    selenium利用Excel进行参数化(简单示例)
  • 原文地址:https://www.cnblogs.com/xiaowuga/p/7277476.html
Copyright © 2020-2023  润新知