从题意,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. web前端利用HSTS(新的Web安全协议HTTP Strict Transport Security)漏洞的超级Cookie(HSTS Super Cookie)

    web前端如果想实现cookie跨站点,跨浏览器,清除浏览器cookie该cookie也不会被删除这似乎有点难,下面的教程让你完全摆脱document.cookie 1.服务器端设置HSTS 如PHP ...

  2. HDU 2227 Find the nondecreasing subsequences(DP)

    Problem Description How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3 ...

  3. 将odbc扩展编译至nodejs程序集中

    1. 下载nodejs https://github.com/joyent/node 2. 下载odbc for nodejs 扩展 https://registry.npmjs.org/odbc/- ...

  4. CSS不常见问题汇总

    写css有一段时间了,其间也遇到一些问题,跟大家分享一下 IE10+滚动条自动以藏问题,导致滚动部分页面看起来不正常 html, body {-ms-overflow-style: scrollbar ...

  5. Linux在device is busy处理

    在Linux管理umount设备时,时常会遇到"device is busy", 假设umount一个文件系统碰到这样的情况.而且你并没有在所需卸载的文件夹下.那么非常可能实用户或 ...

  6. 在.NET Fiddle有趣的沙盒代码

    在.NET Fiddle有趣的沙盒代码 笔者:Tony Patton | 托尼·巴顿译:PurpleEndurer,2014-11-18,第1版 C#和VB.NET开发者能够使用.NET Fiddle ...

  7. 超可爱 纯CSS3实现的小猪、小老鼠、小牛

    原文:超可爱 纯CSS3实现的小猪.小老鼠.小牛 利用纯CSS3绘制一些人物.动物.风景已经不是一件新鲜的事情了,主要是利用CSS3可以让直线变成任意的曲线,于是简单的矢量图形绘制对CSS3来说就小菜 ...

  8. MIFARE系列7《安全》

    飞利浦的MIFARE卡因为它的高安全性在市场上得到广泛应用,比方我们乘车用的公交卡,学校和企业食堂的饭卡等等.它每一个扇区有独立的密匙(6个字节的password),在通信过程中首先要验证密匙才干读写 ...

  9. 他的第一个NDK的Demo

    DEMO下载链接: http://download.csdn.net/detail/logicsboy/7535409 首先给你们恶补下啥是NDK:(我从百度Copy的) NDK全称:Native D ...

  10. zoj 3823 Excavator Contest(结构体)

    题目链接:zoj 3823 Excavator Contest 题目大意:一个人开着挖掘机要在N*N的格子上面移动.要求走全然部的格子.而且转完次数要至少为n*(n-1) - 1次, 而且终点和起点必 ...