[AHOI2002] 芝麻开门 - 数论
求 \(n^k\) 的因子和, \(n \leq 2^{16}, k \leq 20\)
Solution
\]
#include <bits/stdc++.h>
using namespace std;
const int maxlen = 105;
class HP {
public:
int len, s[maxlen];
HP() { (*this) = 0; }
HP(int inte) { (*this) = inte; }
HP(const char *str) { (*this) = str; }
friend ostream &operator<<(ostream &cout, const HP &x);
HP operator=(int inte);
HP operator=(const char *str);
HP operator=(const HP &b);
HP operator*(const HP &b);
HP operator+(const HP &b);
HP operator-(const HP &b);
HP operator/(const HP &b);
HP operator%(const HP &b);
bool operator<(const HP &b);
bool operator>(const HP &b);
int Compare(const HP &b);
};
ostream &operator<<(ostream &cout, const HP &x) {
for (int i = x.len; i >= 1; i--) cout << x.s[i];
return cout;
}
HP HP::operator=(const char *str) {
len = (int)strlen(str);
for (int i = 1; i <= len; i++) s[i] = str[len - i] - '0';
return *this;
}
HP HP::operator=(int inte) {
if (inte == 0) {
len = 1;
s[1] = 0;
return (*this);
}
for (len = 0; inte > 0;) {
s[++len] = inte % 10;
inte /= 10;
}
return *this;
}
HP HP::operator=(const HP &b) {
len = b.len;
for (int i = 1; i <= len; i++) s[i] = b.s[i];
return *this;
}
HP HP::operator*(const HP &b) {
int i, j;
HP c;
c.len = len + b.len;
for (i = 1; i <= c.len; i++) c.s[i] = 0;
for (i = 1; i <= len; i++)
for (j = 1; j <= b.len; j++) c.s[i + j - 1] += s[i] * b.s[j];
for (i = 1; i < c.len; i++) {
c.s[i + 1] += c.s[i] / 10;
c.s[i] %= 10;
}
while (c.s[i]) {
c.s[i + 1] = c.s[i] / 10;
c.s[i] %= 10;
i++;
}
while (i > 1 && !c.s[i]) i--;
c.len = i;
return c;
}
HP HP::operator+(const HP &b) {
int i;
HP c;
c.s[1] = 0;
for (i = 1; i <= len || i <= b.len || c.s[i]; i++) {
if (i <= len)
c.s[i] += s[i];
if (i <= b.len)
c.s[i] += b.s[i];
c.s[i + 1] = c.s[i] / 10;
c.s[i] %= 10;
}
c.len = i - 1;
if (c.len == 0)
c.len = 1;
return c;
}
HP HP::operator-(const HP &b) {
int i, j;
HP c;
for (i = 1, j = 0; i <= len; i++) {
c.s[i] = s[i] - j;
if (i <= b.len)
c.s[i] -= b.s[i];
if (c.s[i] < 0) {
j = 1;
c.s[i] += 10;
} else
j = 0;
}
c.len = len;
while (c.len > 1 && !c.s[c.len]) c.len--;
return c;
}
int HP::Compare(const HP &y) {
if (len > y.len)
return 1;
if (len < y.len)
return -1;
int i = len;
while ((i > 1) && (s[i] == y.s[i])) i--;
return s[i] - y.s[i];
}
bool HP::operator<(const HP &b) {
if (len < b.len)
return 1;
if (len > b.len)
return 0;
int i = len;
while ((i > 1) && (s[i] == b.s[i])) i--;
return s[i] < b.s[i];
}
bool HP::operator>(const HP &b) {
if (len > b.len)
return 1;
if (len < b.len)
return 0;
int i = len;
while ((i > 1) && (s[i] == b.s[i])) i--;
return s[i] > b.s[i];
}
HP HP::operator/(const HP &b) {
int i, j;
HP d(0), c;
for (i = len; i > 0; i--) {
if (!(d.len == 1 && d.s[1] == 0)) {
for (j = d.len; j > 0; j--) d.s[j + 1] = d.s[j];
++d.len;
}
d.s[1] = s[i];
c.s[i] = 0;
while ((j = d.Compare(b)) >= 0) {
d = d - b;
c.s[i]++;
if (j == 0)
break;
}
}
c.len = len;
while ((c.len > 1) && (c.s[c.len] == 0)) c.len--;
return c;
}
HP HP::operator%(const HP &b) {
int i, j;
HP d(0);
for (i = len; i > 0; i--) {
if (!(d.len == 1 && d.s[1] == 0)) {
for (j = d.len; j > 0; j--) d.s[j + 1] = d.s[j];
++d.len;
}
d.s[1] = s[i];
while ((j = d.Compare(b)) >= 0) {
d = d - b;
if (j == 0)
break;
}
}
return d;
}
int n,k,a[99],b[99],top;
HP ans;
int main() {
cin>>n>>k;
ans=1;
int t=n;
for(int i=2;i<=n;i++) {
if(t%i==0) {
a[++top]=i;
}
while(t%i==0) {
b[top]++;
t/=i;
}
}
for(int i=1;i<=top;i++) {
HP tmp=1,xx;
for(int j=1;j<=b[i]*k+1;j++) xx=a[i],tmp=tmp*xx;
xx=1;
tmp=tmp-xx;
xx=a[i]-1;
tmp=tmp/xx;
ans=ans*tmp;
}
cout<<ans;
}
[AHOI2002] 芝麻开门 - 数论的更多相关文章
- 2021record
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- NOIP2014 uoj20解方程 数论(同余)
又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...
- 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)
~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 290 Solved: 148[Submit][Status ...
- bzoj2219: 数论之神
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- hdu5072 Coprime (2014鞍山区域赛C题)(数论)
http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...
- ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德
POJ 1061 青蛙的约会 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Descr ...
随机推荐
- vue循环语句
循环使用 v-for 指令. v-for 指令需要以 site in sites 形式的特殊语法, sites 是源数据数组并且 site 是数组元素迭代的别名. v-for 可以绑定数据到数组来渲染 ...
- Linux 文件|目录 属性
文件属性 ls -l 列出的文件|目录信息如下 第一个字符指定类型,-是文件,d是目录(dir). 后面9个字符是该文件|目录的用户权限:r读,w写,x执行. 执行是指:如果该文件是一个可执行文件, ...
- Android进程永生技术终极揭秘:进程被杀底层原理、APP应对技巧
1.引言 上个月在知乎上发表的由“袁辉辉”分享的关于TIM进程永生方面的文章(即时通讯网重新整理后的标题是:<史上最强Android保活思路:深入剖析腾讯TIM的进程永生技术>),短时间内 ...
- [Contract] Solidity 变量类型的默认值
变量的默认值一般都代表 “零值”. 比如 bool 就是 false,uint.int 就是 0,string 就是空字符串. 其它组合的参考 Solidity 判断 mapping 值的存在 Ref ...
- MySQL分析工具explain介绍
EXPLAIN是MySQl必不可少的一个分析工具,主要用来测试sql语句的性能及对sql语句的优化,或者说模拟优化器执行SQL语句. 简单的说是execute plan, 获取MySQL数据库的执行计 ...
- jmeter导入jmx文件报错:missing class com.thoughtworks.xstream.converters.ConversionException
有的时候我们会参考别人的jmx文件,但是在导入的时候会报错如下图: 实际上是告诉我们缺少jar包所引起的,下载对应jar包放到jmeter安装目录对应的lib/ext下就可以了,如下图: jmeter ...
- 理解一致性Hash算法
简介 一致性哈希算法在1997年由麻省理工学院的Karger等人在解决分布式Cache中提出的,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似.一致性哈希修正了CAR ...
- JAVA面向对象 - 方法重载与覆盖
方法重载 方法重载就是在类的同种实现方式,到底采用哪种方式,取决与调用者给出的参数.方法重载特点是方法名相同,方法的参数类型,个数,顺序至少有一项不同,方法返回类型可以不同,方法的修饰符可以不同,只是 ...
- 2020qbxt游记
csp-s 突破 ----------------------------------------- 1-15 下午才走,这实在是太恶心了.然而因为感冒,当众大佬们都在上学的时候,我在家里睡觉. 2: ...
- 报表生成(POI,jquery.table2excel.js,Echarts)
最近公司要弄个报表相关的功能,话不多说,先上图 前一种是POI 生成的,后一种是Echarts生成的.报表我想大家都不陌生,基本上在公司业务中都会使用到.先说说POI,jquery.table2exc ...