HDU 6063 17多校3 RXD and math(暴力打表题)
One day he wants to calculate:
output the answer module 109+7.
1≤n,k≤1018
p1,p2,p3…pk are different prime numbers
There are exact 10000 cases.
For each test case, there are 2 numbers n,k.
打表大法好啊!打表之后发现就是求n^k%MOD
记得对n先做预处理取模,否则快速幂也救不了啊
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const long long MOD=1e9+; long long quickmod(long long a,long long b,long long m)
{
long long ans = ;
while(b)//用一个循环从右到左遍历b的所有二进制位
{
if(b&)//判断此时b[i]的二进制位是否为1
{
ans = (ans*a)%m;//乘到结果上,这里a是a^(2^i)%m
b--;//把该为变0
}
b/=;
a = a*a%m;
}
return ans;
} int main()
{
long long n,k;
int t=;
while(~scanf("%lld%lld",&n,&k))
{
printf("Case #%d: ",t++);
n%=MOD;
printf("%lld\n",quickmod(n,k,MOD));
}
return ;
}
打表程序如下:
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std; #define MOD 1000000000+7 bool panduan (long long num)
{
long long i;
for(i=;i<=sqrt((double)num)+;i++)
{
if(num%(i*i)==)
return true;
}
return false;
} int main()
{
int n,k;
long long num;
long long res=;
for(int n=;n<=;n++)
for(int k=;k<=;k++)
{
res=;
num=pow((double)n,(double)k);
for(int i=;i<=num;i++)
{
if(!panduan(i))
res+=(long long)(sqrt((double)(num/i)));
res%=MOD;
}
printf("%d %d %lld\n",n,k,res);
}
return ;
}
每一行三个数字分别表示n,k,res
HDU 6063 17多校3 RXD and math(暴力打表题)的更多相关文章
- HDU 6066 17多校3 RXD's date(超水题)
Problem Description As we all know that RXD is a life winner, therefore he always goes out, dating w ...
- HDU 6060 17多校3 RXD and dividing(树+dfs)
Problem Description RXD has a tree T, with the size of n. Each edge has a cost.Define f(S) as the th ...
- HDU 6090 17多校5 Rikka with Graph(思维简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6095 17多校5 Rikka with Competition(思维简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
- HDU 3130 17多校7 Kolakoski(思维简单)
Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...
随机推荐
- js事件流 事件捕获 及时间冒泡详解
Javascript与HTML之间的交互是通过事件实现. 一.事件流 事件,是文档或浏览器窗口中发生的一些特定的交互瞬间.事件流,描述的是页面中接受事件的顺序.IE9,chrome,Firefox,O ...
- ORACLE中ESCAPE关键字用法
ESCAPE用法 1.使用 ESCAPE 关键字定义转义符: 在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符. 2.ESCAPE 'escape_character' 允许在字符串中搜 ...
- Cassandra V2.1.20单机安装
1. 系统调优 [root@sht-sgmhadoopcm- ~]# echo "vm.max_map_count=131072" >> /etc/sysctl.con ...
- nodejs sequelize 对应数据库操作符的定义
const Op = Sequelize.Op [Op.and]: {a: } // 且 (a = 5) [Op.or]: [{a: }, {a: }] // (a = 5 或 a = 6) [Op. ...
- 把旧系统迁移到.Net Core 2.0 日记 (15) --Session 改用Redis
安装Microsoft.Extensions.Caching.Redis.Core NuGet中搜索Microsoft.Extensions.Caching.Redis.Core并安装,此NuGet包 ...
- view的clickable属性和点击background颜色改变
drawable可以是color(color只能是color) android:background=drawable或者color 当一个view(iamge/text view都可以)的andro ...
- body中的onload()函数和jQuery中的document.ready()有什么区别?
1.我们可以在页面中使用多个document.ready(),但只能使用一次onload(). 2.document.ready()函数在页面DOM元素加载完以后就会被调用,而onload()函数则要 ...
- C#中使用FFMPEG切割、合并视频。
参考网址:https://blog.csdn.net/samwang_/article/details/70332924 使用前先确保电脑已经安装了FFMPEG,并且配置好环境变量.检测是否安装配置好 ...
- day039 数据库索引
今日内容: 1.为什么要有索引 简而言之,索引出现的意义是为了更方便,更快速的查询数据. 什么是索引 索引在mysql中也叫''键''或'key'(primary key unique key,ind ...
- java基础巩固之java实现文件上传
对于文件上传,浏览器在上传的过程中是将文件以流的形式提交到服务器端的,如果直接使用Servlet获取上传文件的输入流然后再解析里面的请求参数是比较麻烦,所以一般选择采用apache的开源工具com ...