Codeforces 17D Notepad 简单的数论
从题意,anw = (b-1)*b^(n-1)%c,强调,为了b^(n-1)。
弱渣只能推了宣传。
phi(c)为小于c且与c互质的个数。
当x >= phi(c)时:A^x = A(x%phi(c) + phi(c)) 。
当x < phi(c)时:直接求就可以。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <ctime>
#include <iomanip> #pragma comment(linker, "/STACK:1024000000");
#define EPS (1e-6)
#define _LL long long
#define ULL unsigned long long
#define LL __int64
#define INF 0x3f3f3f3f
#define Mod 1000000007 /** I/O Accelerator Interface .. **/
#define g (c=getchar())
#define d isdigit(g)
#define p x=x*10+c-'0'
#define n x=x*10+'0'-c
#define pp l/=10,p
#define nn l/=10,n
template<class T> inline T& RD(T &x)
{
char c;
while(!d);
x=c-'0';
while(d)p;
return x;
}
template<class T> inline T& RDD(T &x)
{
char c;
while(g,c!='-'&&!isdigit(c));
if (c=='-')
{
x='0'-g;
while(d)n;
}
else
{
x=c-'0';
while(d)p;
}
return x;
}
inline double& RF(double &x) //scanf("%lf", &x);
{
char c;
while(g,c!='-'&&c!='.'&&!isdigit(c));
if(c=='-')if(g=='.')
{
x=0;
double l=1;
while(d)nn;
x*=l;
}
else
{
x='0'-c;
while(d)n;
if(c=='.')
{
double l=1;
while(d)nn;
x*=l;
}
}
else if(c=='.')
{
x=0;
double l=1;
while(d)pp;
x*=l;
}
else
{
x=c-'0';
while(d)p;
if(c=='.')
{
double l=1;
while(d)pp;
x*=l;
}
}
return x;
}
#undef nn
#undef pp
#undef n
#undef p
#undef d
#undef g
using namespace std; char s[1000010];
int B[1000010],N[1000010];
LL c,b,n; bool vis[1000010];
LL prime[1000010];
int Top; LL Euler(LL n)
{
LL ret=1,i;
for(i=2; i*i<=n; i++)
{
if(n%i==0)
{
n/=i,ret*=i-1;
while(n%i==0)
n/=i,ret*=i;
}
}
if(n>1)
ret*=n-1;
return ret;
} LL Cal(int *n,LL c,bool &mark)
{
LL re = 0; for(int i = 0; n[i] != -1; ++i)
{
re *= 10,re += n[i];
if(re >= c)
mark = true,re %= c;
}
return re;
} LL qm(LL a,LL b,LL n)
{
LL ret=1;
LL tmp=a;
while(b)
{
if(b&1) ret=ret*tmp%n;
tmp=tmp*tmp%n;
b>>=1;
}
return ret;
} int main()
{
int i,j; scanf("%s",s);
for(i = 0; s[i] != '\0'; ++i)
B[i] = s[i]-'0';
B[i] = -1; scanf("%s",s);
for(i = 0; s[i] != '\0'; ++i)
N[i] = s[i]-'0';
N[i] = -1; scanf("%I64d",&c); LL MAXN = sqrt(c);
memset(vis,false,sizeof(vis));
Top = 0; for(i = 2; i <= MAXN; ++i)
if(vis[i] == false)
for(j = i+i,prime[Top++] = i; j <= MAXN; j += i)
vis[j] = true; LL phi = Euler(c),b1;
bool mark = false;
b = Cal(B,c,mark);
mark = false;
n = Cal(N,phi,mark);
b1 = (b-1+c)%c; if(mark == true)
n = (n-1+phi)%phi + phi;
else
n--; LL anw = b1*qm(b,n,c)%c; if(anw == 0)
anw = c;
printf("%I64d\n",anw); return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Codeforces 17D Notepad 简单的数论的更多相关文章
- codeforces 17D Notepad
codeforces 17D Notepad 题意 题解 TBD 更新模板(phi.欧拉降幂) 代码 #include<bits/stdc++.h> using namespace std ...
- CodeForces 17D Notepad(同余定理)
D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...
- [CodeForces - 1225D]Power Products 【数论】 【分解质因数】
[CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- CodeForces - 573A (简单数论+模拟)
题意 https://vjudge.net/problem/CodeForces-573A 有n个数ai ,你可以把每个数任意次×2 或×3 ,问能否最终使得每个数相等. 思路 x2和x3只能改变数 ...
- Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...
- Codeforces 837D Round Subset - 动态规划 - 数论
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...
- Codeforces 55D (数位DP+离散化+数论)
题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...
- Codeforces 41D Pawn 简单dp
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...
随机推荐
- Nginx + unicorn 运行多个Rails应用程序
PS:第一次写的很详细,可惜发布失败,然后全没了,这是第二次,表示只贴代码,剩下的自己领悟好了,这就是所谓的一鼓作气再而衰吧,希望没有第三次. 版本: ruby 2.1.0 rails 4.0.2 n ...
- HTTP简单的解析协议
1.HTTP定义的协议 官方的定义: WWW这是Internet作为传输介质的应用.WWW主变速器单元是在线Web网页.WWW它正在给客户/server计算模型,由Web浏览器Webse ...
- Hadoop 它们的定义Writable NullpointerException
Hadoop周边环境:Hadoop2.4 定义中的Hadoop的Writable时间,有时你需要使用数组,而不是简单的单一值或串.例如,下面的代码: package test; import java ...
- Android Context MODE的四种模式解析(转)
Context.MODE_PRIVATE:为默认操作模式,代表该文件是私有数据,只能被应用本身访问,在该模式下,写入的内容会覆盖原文件的内容,如果想把新写入的内容追加到原文件中.可以使用Context ...
- R语言做文本挖掘 Part5情感分析
Part5情感分析 这是本系列的最后一篇文章,该.事实上这种单一文本挖掘的每一个部分进行全部值获取水落石出细致的研究,0基础研究阶段.用R里面现成的算法,来实现自己的需求,当然还參考了众多网友的智慧结 ...
- 【ORACLE】使用数据泵的生产环境impd,expdp数据迁移
********************************************** ** 原文: blog.csdn.net/clark_xu 徐长亮专栏 **************** ...
- Linux核心设计依据(七)系统调用
我理解的系统调用,用户进程和内核是内核提供了一个接口进行交互.除了异常和下降外.内核系统调用是唯一合法入境.像/proc还通过系统调用访问. 系统调用的意义: 让用户进程受限地訪问硬件设备 为用户空间 ...
- easyUI 插件写法 ---Validatebox 插件为例
easyui 的每个组件都有属性.方法和事件.用户可以很容易地对这些组件进行扩展. js地址:jquery-easyui-1.3.3/jeasyui-extensions/jeasyui.extens ...
- React.js再探(二)
上文中说到了组件了. 我们使用组件的目的最大莫过于复用,提供生产效率. 那么,这时候组件就应该能够提供一些”api”出来,让开发者去定义在不同场景下的不同表现,比如,行为或外观等. 而这些“api”就 ...
- oracle_分区表的新增、修改、删除、合并。普通表转分区表方法
一. 分区表理论知识Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Oracl ...