hdu5666 Segment (俄罗斯乘法)
来源:互联网 发布:犀牛软件培训上海 编辑:程序博客网 时间:2024/04/28 19:34
题目链接:点这里!!!!
题意:求(q-1)*(q-2)%p,(1<=q<=1e18,q is primer, 1<=p<=1e18)
题解:直接俄罗斯乘法就可以了。
俄罗斯乘法:点这里!!
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<sstream>#include<algorithm>#include<vector>#include<bitset>#include<set>#include<queue>#include<stack>#include<map>#include<cstdlib>#include<cmath>#define PI 2*asin(1.0)#define LL long long#define pb push_back#define pa pair<int,int>#define clr(a,b) memset(a,b,sizeof(a))#define lson lr<<1,l,mid#define rson lr<<1|1,mid+1,r#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x)#define key_value ch[ch[root][1]][0]C:\Program Files\Git\binconst int MOD = 1000000007;const int N = 500+15;const int maxn = 60000+1000;const int letter = 130;const int INF = 1e17;const double pi=acos(-1.0);const double eps=1e-8;using namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}LL p,q,x,y;LL cc(LL a,LL b){ LL ans=0,pc=a; while(b){ if(b&1){ ans=(ans+pc)%p; b--; } else { pc=(pc*2)%p; b=b/2; } } return ans;}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%I64d%I64d",&q,&p); if(q<=2) {puts("0");continue;} LL x,y; if((q-2)&1) x=q-2,y=(q-1)/2ll; else x=(q-2)/2ll,y=q-1; LL ans=cc(x,y); printf("%I64d\n",ans); } return 0;}
0 0
- hdu5666 Segment (俄罗斯乘法)
- HDU5666-Segment
- 【HDU 5666 Segment】+ 俄罗斯乘法
- hdoj 5666 Segment (大数取模)(俄罗斯乘法)
- HDU 5666 Segment —— 快速加 俄罗斯农民乘法
- 俄罗斯乘法
- 俄罗斯乘法
- hdu5666
- 俄罗斯农夫乘法(减治法)
- BC#80 Segment 慢速乘法
- hdoj 5666 Segment 【二进制优化乘法】
- hdu 5666 Segment(大整数乘法)
- 俄罗斯
- 算法_俄罗斯农夫法的乘法算法
- hdu5666 BestCoder Round #80
- BC #80 B Segment(快速乘法、坑)
- HDU 5666 Segment(快速乘法/快速幂改)
- Hdu 5666 Segment【欧拉函数+技巧乘法】
- 使用CocoaPods被卡住:Updating local specs repositories
- 南京理工大学第八届程序设计大赛(校外镜像)
- Thread pool FAQ
- 正常cocoapods安装好的情况下如何安装pod
- 使用nmap绕过防火墙进行扫描
- hdu5666 Segment (俄罗斯乘法)
- LightOj 1370(素数筛选打表)
- jspNote
- objective-c 屏幕截图
- VS2008 快捷键大全
- 这恼人的一星期
- 进程间通信方式之有名管道
- 使用 malloc后free出错 错误所在
- c#下载网页图片