RXD and math

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 568    Accepted Submission(s): 306

Problem Description
RXD is a good mathematician.
One day he wants to calculate:

∑i=1nkμ2(i)×⌊nki−−−√⌋

output the answer module 109+7.
1≤n,k≤1018

μ(n)=1(n=1)
μ(n)=(−1)k(n=p1p2…pk)
μ(n)=0(otherwise)

p1,p2,p3…pk are different prime numbers

Input
There are several test cases, please keep reading until EOF.
There are exact 10000 cases.
For each test case, there are 2 numbers n,k.
 
Output
For each test case, output "Case #x: y", which means the test case number and the answer.
Sample Input
10 10
 
Sample Output
Case #1: 999999937
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6066 6065 6064 6063 6062 

题解:n^k % mod

注意 :n因为非常大所以在开始就要先用 mod 运算一遍

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
using namespace std;
const long long m=1e9+;
long long n,k;
long long solve(long long a,long long b)
{
a=a%m;
long long ans=;
while(b)
{
if (b&)ans=(ans*a)%m;
b>>=;
a=(a*a)%m;
}
return ans;
}
int main()
{
int cas=;
while(scanf("%lld%lld",&n,&k)!=EOF)
{
printf("Case #%d: %lld\n",++cas,solve(n,k));
}
return ;
}

hdu 6063 RXD and math(快速幂)的更多相关文章

  1. HDU 6063 - RXD and math | 2017 Multi-University Training Contest 3

    比赛时候面向过题队伍数目 打表- - 看了题解发现确实是这么回事,分析能力太差.. /* HDU 6063 - RXD and math [ 数学,规律 ] | 2017 Multi-Universi ...

  2. HDU - 6063 RXD and math

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6063 打表发现规律是n^k #include <iostream> #inc ...

  3. 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)

    题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...

  4. 数学--数论--HDU 6063 RXD and math (跟莫比乌斯没有半毛钱关系的打表)

    RXD is a good mathematician. One day he wants to calculate: output the answer module 109+7. p1,p2,p3 ...

  5. HDU.1575 Tr A ( 矩阵快速幂)

    HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...

  6. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  7. hdu 2604 Queuing(矩阵快速幂乘法)

    Problem Description Queues and Priority Queues are data structures which are known to most computer ...

  8. HDU 2842 (递推+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...

  9. HDU 4704 Sum (费马定理+快速幂)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

随机推荐

  1. jstack用法

    第一步先找出Java进程ID,我部署在服务器上的Java应用名称为mrf-center: root@ubuntu:/# ps -ef | grep mrf-center | grep -v grep ...

  2. 伪类 :after 清除浮动的原理和方法

    浮动元素容器的clearing问题1. 问题的由来有这样一种情形:在一个容器(container)中,有两个浮动的子元素.<div>        <div style=" ...

  3. JS正则表达式从入门到入土(9)—— test方法以及它的那些坑

    test方法 test方法介绍 RegExp.prototype.test(str) test方法用于测试字符串参数中是否存在匹配正则表达式模式的字符串 test方法的使用 let reg = /\w ...

  4. Greatest Common Increasing Subsequence

    /*HDU1423 最长公共递增*/ #include <stdio.h> #include <string.h> #include <iostream> usin ...

  5. Python3.x:打包为exe执行文件(window系统)

    Python3.x:打包为exe执行文件(window系统) window系统下发布: 一.安装pyinstaller(PyInstaller 3.3.1) cmd安装命令: pip install ...

  6. RocEDU.阅读.写作《乌合之众》(二)

    第二卷 群体的意见与信念 决定着群体意见与信念的因素分为两类:直接因素与间接因素. 直接因素:使观念采取一定形式并且使它能够产生一定结果的因素. 间接因素:能够使群体接受某些信念并使其难以接受别的信念 ...

  7. BootStrap实现图片轮播

    <div class="container">        <div data-ride="carousel" id="carou ...

  8. Can't connect to any repository: xxxxxx Error writing request body to server

    今天在git提交代码时一直报如下错误: Can't connect to any repository: https://gitee.com/xxxxxx(https://gitee.com/xxxx ...

  9. 【jdk源码分析】java多线程开启的三种方式

    1.继承Thread类,新建一个当前类对象,并且运行其start()方法 package com.xiaostudy.thread; /** * @desc 第一种开启线程的方式 * @author ...

  10. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...