从题意,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. POJ 1631 Bridging signals(LIS 二分法 高速方法)

    Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1076 ...

  2. Windows编译Nodejs时遇到 File "configure", line 313 SyntaxError: invalid syntax Failed to create vc project files. 时的解决方法

    第一次编译的时候电脑上未安装python,遂下载了python最新版本3.3.3,但是报了下面这个错误. 把python降到2.7.*的版本即可. 我这里测试2.7.6和2.7.3版本可以正常编译.

  3. Serializable 作用

    Serializable 作用 序列化的attribute,是为了利用序列化的技术 准备用于序列化的对象必须设置 [System.Serializable] 标签,该标签指示一个类能够序列化. 便于在 ...

  4. Partitioner分区过程分析

    Partition中国人意味着分区,意义的碎片,这个阶段也是整个MapReduce该过程的第三阶段.在Map返回任务,是使key分到通过一定的分区算法.分到固定的区域中.给不同的Reduce做处理,达 ...

  5. 百度echarts扇形图每个区块增加点击事件

    效果图:操作人员要求 :我想看这个扇形图对应的 页面信息,给我加个链接跳转:原先的chart.js发现没有api,后来改用百度的echart.js <!DOCTYPE html> < ...

  6. 网络语音视频技术浅议 Visual Studio 2010(转)

    我们在开发实践中常常会涉及到网络语音视频技术.诸如即时通讯.视频会议.远程医疗.远程教育.网络监控等等,这些网络多媒体应用系统都离不开网络语音视频技术.本人才疏学浅,对于网络语音视频技术也仅仅是略知皮 ...

  7. 深入理解Android View(转)

    做android其实也有一段时间了,我们每个人都会碰到一些这样或那样的问题,碰到问题了就拼命百度,可是发现,我们解决问题的能力并没有提升很多,所以我才有想总结一下我项目中所用过的相关知识,并了解一下A ...

  8. 5、VS2010+ASP.NET MVC4+EF4+JqueryEasyUI+Oracle该项目的开发——使用datagrid做报表

    来点需要:我使用的数据库访问EF框架,但是,因为使用一个动态表来的统计报告中.单独是每天产生基于数据表,它是很难使用EF加盟前.所以我包装在两组数据库存取层的框内,一个是EF,一种是传统的ADO.NE ...

  9. IOS ARC和非ARC文件混用

    ARC在SDK4.0的时候增加的,因为要和曾经的项目融合,就会有arc和非arc文件的混合. 当然,也就这两种情况: 1.自己的旧项目没有使用ARC,可是引入的第三方库却是使用了ARC的. 2.自己的 ...

  10. JavaScript编写了一个计时器

    初学JavaScript,用JavaScript编写了一个计时器. 设计思想: 1.借助于Date()对象,来不断获取时间点: 2.然后用两次时间点的毫秒数相减,算出时间差: 3.累加时间差,这样就能 ...