从题意,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 简单的数论的更多相关文章

  1. codeforces 17D Notepad

    codeforces 17D Notepad 题意 题解 TBD 更新模板(phi.欧拉降幂) 代码 #include<bits/stdc++.h> using namespace std ...

  2. CodeForces 17D Notepad(同余定理)

    D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...

  3. [CodeForces - 1225D]Power Products 【数论】 【分解质因数】

    [CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...

  4. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

  5. CodeForces - 573A (简单数论+模拟)

    题意 https://vjudge.net/problem/CodeForces-573A 有n个数ai​ ,你可以把每个数任意次×2 或×3 ,问能否最终使得每个数相等. 思路 x2和x3只能改变数 ...

  6. Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法

    Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...

  7. 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 ...

  8. Codeforces 55D (数位DP+离散化+数论)

    题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...

  9. Codeforces 41D Pawn 简单dp

    题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...

随机推荐

  1. Codeforces 338D GCD Table 中国剩余定理

    主题链接:点击打开链接 特定n*m矩阵,[i,j]分值为gcd(i,j) 给定一个k长的序列,问能否匹配上 矩阵的某一行的连续k个元素 思路: 我们要求出一个解(i,j) 使得 i<=n &am ...

  2. android Intent.createChooser 应用选择

    在微博案例: 1.public void onClickShare(View view) { 2. 3. Intent intent=new Intent(Intent.ACTION_SEND); 4 ...

  3. error LNK2019: 解析的外部符号 __imp__DispatchMessageW@4,在函数的符号 _WinMain@16 据引述

    错误: 1>WinMain.obj : error LNK2019: 解析的外部符号 __imp__DispatchMessageW@4,在函数的符号 _WinMain@16 据引述 1> ...

  4. HTML5学习笔记简明版(10):过时的元素和属性

    被遗弃的元素(Element) 这个小节里列出的元素在HTML5里将不再使用,现有文档升级到 HTML5的话能够使用一些替代方案.比如parser section 能够处理isindex 元素的功能. ...

  5. ARP协议的基础知识

          关于ARP协议的基础知识 1.ARP的工作原理 本来我不想在此重复那些遍地都是的关于ARP的基本常识,但是为了保持文章的完整性以及照顾初学者,我就再啰嗦一些文字吧,资深读者可以直接跳过此节 ...

  6. CIC and Fir 滤波器的级联

    在FDATool中 CIC 和 Fir 级联滤波器的设计 1 设计CIC滤波器的幅频特性曲线如下 2.设计FIR 滤波器的幅频特性曲线如下 3.总的特性曲线如下 4.把通带部分放大后的图,比较平坦

  7. Elasticsearch教程

    Elasticsearch教程 摘要: 参考资料Elasticsearch中文参考文档思维导图阅读全文 posted @ 2015-08-05 11:49 xingoo 阅读(18) | 评论 (0) ...

  8. react.js 从零开始(六)Reconciliation

    Reconciliation   React 的关键设计目标是使 API 看起来就像每一次有数据更新的时候,整个应用重新渲染了一样.这就极大地简化了应用的编写,但是同时使 React 易于驾驭,也是一 ...

  9. HTML5 Web SQL Database 与 Indexed Database 的 CRUD 操作

    http://www.ibm.com/developerworks/cn/web/1210_jiangjj_html5db/ 版权声明:本文博客原创文章,博客,未经同意,不得转载.

  10. Redis实现高并发分布式序列号

    使用Redis实现高并发分布式序列号生成服务 序列号的构成 为建立良好的数据治理方案,作数据掌握.分析.统计.商业智能等用途,业务数据的编码制定通常都会遵循一定的规则,一般来讲,都会有自己的编码规则和 ...