题目:这里

题意:在线段x+y=q与坐标轴围成的三角形中,求有多少个坐标为整数的点,答案模上p。

很容易就想到最后答案就是((q-1)*(q-2))/2然后模上p就是了,但是这个数字比较大,相乘会爆long long,于是用二进制的乘法,类似于快速幂,另外注意这个除以2得在

之前就处理了,因为最后答案一定要是个准确的整数。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; typedef long long ll; ll jjc(ll x,ll y,ll mod)
{
ll res=;
for ( ; y> ; y>>=)
{
if (y&) res=(res%mod+x%mod)%mod;
x=(x%mod+x%mod)%mod;
}
return res;
} int main()
{
int t;
scanf("%d",&t);
while (t--){
ll q,p;
scanf("%I64d%I64d",&q,&p);
ll q1=q-;ll q2=q-;
if (q1&) q2/=;
else q1/=;
printf("%I64d\n",jjc(q1,q2,p));
}
return ;
}

hdu 5666 (大数乘法) Segment的更多相关文章

  1. HDU 1402 大数乘法 FFT、NTT

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. hdu-5666 Segment(俄罗斯乘法or大数乘法取模)

    题目链接: Segment Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) P ...

  3. HDOJ-1042 N!(大数乘法)

    http://acm.hdu.edu.cn/showproblem.php?pid=1042 题意清晰..简单明了开门见山的大数乘法.. 10000的阶乘有35000多位 数组有36000够了 # i ...

  4. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  5. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  6. 用分治法实现大数乘法,加法,减法(java实现)

    大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O(n^2),基本思想是把多项式A(x)与B(x)写成 A(x)=a*x^m+b B(x)=c*x^m+d 其中a,b,c ...

  7. 51 Nod 1027 大数乘法【Java大数乱搞】

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度  ...

  8. 51 Nod 1028 大数乘法 V2【Java大数乱搞】

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...

  9. hdu_1042(模拟大数乘法)

    计算n! #include<cstring> #include<cstdio> using namespace std; ]; int main() { int n; whil ...

随机推荐

  1. CenOS 7 安装mysql

    1:安装YUM源 2:利用file zilla 将mysql文件拖放到 /var/opt  目录下 3:在centos当中,已经将mysql的文件放到了 /var/opt  我们只需要安装就可以 安装 ...

  2. 报错:Unable to load configuration. - action - file:/E:/apache-tomcat-8.0.37/webapps/20161102-struts2-3/WEB-INF/classes/struts.xml:11:73

    第一种报错: 严重: Exception starting filter struts2Unable to load configuration. - action - file:/E:/apache ...

  3. eclipse 代码自动提示

    从Window -> preferences -> Java -> Editor -> Content assist -> Auto-Activation下,我们可以在& ...

  4. python 将字典的键&值从byte类型转换为str类型

    def convert(data): if isinstance(data, bytes): return data.decode('ascii') if isinstance(data, dict) ...

  5. 直接解压msi文件

    msiexec /a "F:\TDDownload\subversion-1.5.5.msi" /qb TARGETDIR="F:\TDDownload\subversi ...

  6. [CF225C] Barcode (简单DAG上dp)

    题目链接:http://codeforces.com/problemset/problem/225/C 题目大意:给你一个矩阵,矩阵中只有#和.两种符号.现在我们希望能够得到一个新的矩阵,新的矩阵满足 ...

  7. 关于对inputstream流的复制

    今天因为项目需要,获取到一个inputstream后,可能要多次利用它进行read的操作.由于流读过一次就不能再读了,所以得想点办法. 而InputStream对象本身不能复制,因为它没有实现Clon ...

  8. 12. Linux在线升级yum

    软件包仓库源 将yum源放在/etc/yum.repo.d root@cfm880 Packages]# cd /etc/yum.repos.d/[root@cfm880 yum.repos.d]# ...

  9. libssh2 的集成与应用

    http://blog.csdn.net/wyc6668205/article/details/9179197 Xmanager Enterprise 4 putty 等工具都功能都是利用libssh ...

  10. Python自动化 【第五篇】:Python基础-常用模块

    目录 模块介绍 time和datetime模块 random os sys shutil json和pickle shelve xml处理 yaml处理 configparser hashlib re ...