code force 1228C
算是一题普通数论+思维题吧。
大概很多人是被题意绕晕了。
思路:
首先常规操作求出X的质因子。
然后题目要求的是,X的每个质因子p,在g(i,p)的连乘。i∈[1,n];
我们转换下思维,不求每一个g(i,p)中最终是哪些 p的幂次,而是反求 每个p的幂次对结果的贡献。
显而易见,p^k在1~n的出现的次数就是 [n/(p^k)].
这样枚举所有质因子,计算中再利用快速幂取模便可以得到答案
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#pragma GCC optimize(2)
#include <bits/stdc++.h> using namespace std;
typedef double dou;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii; #define pai acos(-1.0)
#define M 200007
#define inf 0x3f3f3f3f
#define mod 1000000007
#define IN inline
#define W(a) while(a)
#define lowbit(a) a&(-a)
#define left k<<1
#define right k<<1|1
#define lson L, mid, left
#define rson mid + 1, R, right
#define ms(a,b) memset(a,b,sizeof(a))
#define Abs(a) (a ^ (a >> 31)) - (a >> 31)
#define random(a,b) (rand()%(b+1-a)+a)
#define false_stdio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) ll x, n;
ll ans = ;
vector<ll>num; void init(ll tmp) {
for (ll i = ; i * i <= tmp; i++) {
if (tmp % i == ) {
num.push_back(i);
W(tmp % i == )tmp /= i;
}
}
if (tmp != )num.push_back(tmp);
} ll Pow(ll base, ll sup) {
ll sum = ;
W(sup) {
if (sup & )sum = (sum * base) % mod;
sup >>= ;
base = (base * base) % mod;
}
return sum % mod;
} int main() {
false_stdio;
cin >> x >> n;
init(x);
for (auto p : num) {
ll tmp = ;
W(tmp <= n / p) {//条件应该理解为 tmp*p<=n,而n%p==0,所以可以利用除法防止爆精度
tmp *= p;
ans = (ans * Pow(p, n / tmp)) % mod;
}
}
cout << ans << endl;
return ;
}
code force 1228C的更多相关文章
- pycharm debug后会出现 step over /step into/step into my code /force step into /step out 分别表示
1.debug,全部打印 2.打断点debug,出现单步调试等按钮,只运行断点前 3.setup over 调试一行代码 4.setup out 运行断点后面所有代码 5.debug窗口显示调试按钮 ...
- 【Code Force】Round #589 (Div. 2) D、Complete Tripartite
题目链接 大致题意 把一个图分成三块,要求任意两块之间是完全图,块内部没有连线 分析 首先根据块内没有连线可以直接分成两块 假定点1是属于块1的,那么所有与点1连接的点,都不属于块1:反之则是块1的 ...
- code force 424 A - Office Keys
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- code force 403C.C. Andryusha and Colored Balloons
C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes ...
- code force 403B.B. The Meeting Place Cannot Be Changed
B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...
- code force 401B. Game of Credit Cards
B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Code Force 21B Intersection
B. Intersection time limit per test1 second memory limit per test256 megabytes inputstandard input o ...
- Code Force 429B Working out【递推dp】
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...
- .htaccess 基础教程(三)RewriteCond标志符,RewriteRule适用的标志符
1.利用 .htaccess 防止盗链 如果不喜欢别人在他们的网页上链接自己的图片.文档的话,也可以通过htaccess的指令来做到.当然这样也可以对你的网站服务器压力变小! 这次先给出‘代码’,然后 ...
随机推荐
- java内部类 2.19
1.定义了成员内部类后,必须使用外部类对象来创建内部类对象,而不能直接去 new 一个内部类对象,即:内部类 对象名 = 外部类对象.new 内部类( ); //外部类HelloWorld publi ...
- gem5-gpu 全系统FS模式 系统调用SE模式
SE模式中无线程调度器,只能运行单线程程序,如SPEC CPU 2006,仅模拟片上CPU.GPU.Network和DRAM等. FS模式需加载虚拟Linux和磁盘,Linux负责线程调度.实现了Pt ...
- LeetCode455 分发饼干(简单贪心—Java优先队列简单应用)
题目: 假设你是一位很棒的家长,想要给你的孩子们一些小饼干.但是,每个孩子最多只能给一块饼干.对每个孩子 i ,都有一个胃口值 gi ,这是能让孩子们满足胃口的饼干的最小尺寸:并且每块饼干 j ,都有 ...
- NRF51822和NRF52832的主要区别
对于NRF51822和NRF52832的选择性相信大家也是非常困惑的,哪个性价比高?下面为大家讲下NRF51822和NRF52832的一个区别,让大家能够更好的快速选型加快研发产品进度! 主要分为 ...
- PhotoView 实现与图片进行简单的交互
本文的category是根据VIPhotoView来做参考,在此基础上添加个加载网络图片. 此category主要功能是与图片进行交互,双击放大图片,捏合等操作. 感谢vitoziv ! VIPhot ...
- LCT(1)
LCT(Link-Cut Tree,动态树)是一个支持动态修改树的结构的数据结构,其基本操作有 \(\texttt{access}\) , \(\texttt{findroot}\) , \(\tex ...
- ZOJ 3791 An easy game DP+组合数
给定两个01序列,每次操作可以任意改变其中的m个数字 0变 1 1 变 0,正好要变化k次,问有多少种变法 dp模型为dp[i][j],表示进行到第i次变化,A,B序列有j个不同的 变法总和. 循环 ...
- java基础源码 (2)--StringBuilder类
Serializable(接口): 是一个IO的序列化接口,实现了这个接口,就代表这个类可以序列化或者反序列化,该接口没有方法或者字段,仅用于标识可串行话的语义. Appendable(接口): /* ...
- 面向对象-接口(interface)实战案例
面向对象-接口(interface)实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.接口(interface)概述 1>.接口的语法格式 接口时抽象类的一种特殊体 ...
- 找《飘》 中最常用的N个单词。
找<飘> 中最常用的N个单词. 1,题目:输出单个文件(<飘> 英文版)中的前 N 个最常出现的英语单词,并将结果输入到文本文件中. 2,设计思路: 1),按行依次读取文件并按 ...