ACDream - Power Sum
先上题目:
Power Sum
Problem Description
Input
第一行一个数T( <= 10),表示数据总数
然后每行给出3个数n,m,p(1 <= n <= m <= 10^18, 1 <= p <= 10^6, p是质数
Output
Sample Input
2
1 1 11
3 2 11
Sample Output
1
3
Hint

#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
#define MAX 1000002
using namespace std; LL n,m,p,ti; bool f[MAX];
LL mm[MAX];
LL ans,rr,r; LL Fast_Mod(LL i,LL t){
LL a = ;
while(t){
if(t&) a = i*a%p;
i = (i%p)*(i%p)%p;
t>>=;
}
return a;
} void solve1(){
ans=;
memset(f,,sizeof(f));
for(int i=;i<=p;i++) mm[i]=;
LL u;
f[]=;
for(LL i=;i<=p;i++){
if(!f[i]){
mm[i] = Fast_Mod(i,m);
for(LL j=i+i;j<=p;j+=i){
f[j]=;
u = j;
while(u%i==){
u/=i;
mm[j]=mm[j]*mm[i]%p;
}
}
}
ans = (ans + mm[i])%p;
if(i<=r) rr=ans;
}
} void solve2(){
ans=;
memset(f,,sizeof(f));
for(int i=;i<=r;i++) mm[i]=;
LL u;
f[]=;
for(LL i=;i<=r;i++){
if(!f[i]){
mm[i] = Fast_Mod(i,m);
for(LL j=i+i;j<=r;j+=i){
f[j]=;
u = j;
while(u%i==){
u/=i;
mm[j]=mm[j]*mm[i]%p;
}
}
}
ans = (ans + mm[i])%p;
}
} int main()
{
int t;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%lld %lld %lld",&n,&m,&p);
ti = n/p;
r = n%p;
rr=;
if(ti!=){
solve1();
ans = (ans*ti)%p;
ans = (ans+rr)%p;
}else{
solve2();
}
printf("%lld\n",ans);
}
return ;
}
Power Sum
ACDream - Power Sum的更多相关文章
- Power Sum 竟然用原根来求
Power Sum Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitS ...
- acdream Divide Sum
Divide Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitSta ...
- ACdream: Sum
Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticN ...
- acdream 1431 Sum vs Product
Sum vs Product Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...
- ACdream 1431——Sum vs Product——————【dfs+剪枝】
Sum vs Product Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) S ...
- ACDream - Lowbit Sum
先上题目: C - Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others ...
- hdu3208 Power of Integer
/** 题目:H - Power of Integer 链接:https://vjudge.net/contest/152887#problem/H 题意:给出区间[a, b],问你区间[a, b]所 ...
- 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: FINAL
Stat2.3x Inference(统计推断)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...
- JavaScript基础--简单功能的计算器(十一)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- Git是什么?
Git是目前世界上最先进的分布式版本控制系统(没有之一). Git有什么特点?简单来说就是:高端大气上档次! 那什么是版本控制系统? 如果你用Microsoft Word写过长篇大论,那你一定有这样的 ...
- CockroachDB——类似spanner的开源版,底层使用rocksdb存储,mvcc,支持事务,raft一致性,licence是CockroachDB Community License Agreement
摘自:https://github.com/cockroachdb/cockroach/blob/master/docs/design.md CockroachDB is a distributed ...
- (Go)11.九九乘法表示例
//九九乘法表 package main import ( "fmt" ) func chengfa() { ; m < ; m ++ { ; n <= m; n++ ...
- IPv6系列-初学者的10个常见困扰
本文是<IPv6系列>文章的第二篇<常见困扰>,紧接<入门指南>,用于解答IPv6的10个常见困扰. 小慢哥的原创文章,欢迎转载 目录 ▪ 本文缘由 ▪ 困扰1. ...
- prim解决最小生成树问题
#include <iostream> #include <algorithm> #include <stdio.h> #include <math.h> ...
- CSS3 中弹性盒模型--容器的属性
1.display : flex | inline-flex注意,设为 Flex 布局以后,子元素的float.clear和vertical-align属性 将失效. 2.flex-direction ...
- Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have A
Django:提交表单报错:RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you ...
- Elasticsearch之curl删除
扩展下, Elasticsearch之curl删除索引库 [hadoop@djt002 elasticsearch-2.4.3]$ curl -XDELETE 'http://192.168.80.2 ...
- 如何使用SQL Developer创建数据库连接
SQL Develope启动后,需要创建一个数据库连接,只有创建了数据库连接,才能在该数据库的方案中创建.更改对象或编辑表中的数据. 创建数据库连接的步骤如下. (1)在主界面左边窗口的“连接”选项卡 ...
- 深入浅出java多态
所谓多态就是指程序中定义的引用变量所指向的具体类型和通过该引用变量发出的方法调用在编程时并不确定,而是在程序运行期间才确定,即一个引用变量倒底会指向哪个类的实例对象,该引用变量发出的方法调用到底是哪个 ...