Segment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
    Silen August does not like to talk with others.She like to find some interesting problems.

Today she finds an interesting problem.She finds a segment x+y=q.The segment intersect the axis and produce a delta.She links some line between (0,0) and the node on the segment whose coordinate are integers.

Please calculate how many nodes are in the delta and not on the segments,output answer mod P.

 
Input
    First line has a number,T,means testcase number.

Then,each line has two integers q,P.

q is a prime number,and 2≤q≤1018,1≤P≤1018,1≤T≤10.

 
Output
    Output 1 number to each testcase,answer mod P.
 
Sample Input
1
2 107
 
Sample Output
0
 
Source
题解:答案就是((p-1)*(p-2)/2)%mod;p是10^18以内直接乘就会爆;利用俄罗斯乘法的加法性质得到答案;(现场做只会想到java大数。。果然菜鸟。。。)
   俄罗斯乘法:http://baike.baidu.com/link?url=vVo1zdml29g80N-BYvpdm2hNGpYwSnGoJsnAJmook4AJBiYUVL_ort5f7XqFJ0yx6zxB5ha90q6-1LD6HxPIaa
俄罗斯乘法代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define inf 2000000001
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
ll eluosimul(ll x,ll y,ll mod)
{
ll sum=;
while(x)
{
if(x&)
{
sum+=y;
sum%=mod;
}
x>>=;
y*=;
y%=mod;
}
return sum;
}
int main()
{
ll x,y,z,i,t,m,q;
scanf("%I64d",&x);
while(x--)
{
ll ans;
scanf("%I64d%I64d",&q,&m);
if(q%)
ans=eluosimul(q-,(q-)/,m);
else
ans=eluosimul(q-,(q-)/,m);
printf("%I64d\n",ans);
}
return ;
}

java:

import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int x;
x=cin.nextInt();
while(x!=)
{
x--;
BigInteger c=new BigInteger("");
BigInteger e=new BigInteger("");
BigInteger a=cin.nextBigInteger();
BigInteger d=a.subtract(c);
BigInteger f=a.subtract(e);
BigInteger b=cin.nextBigInteger();
BigInteger ans=f.multiply(d);
ans=ans.divide(c);
System.out.println(ans.remainder(b));
}
}
}

hdu 5666 Segment 俄罗斯乘法或者套大数板子的更多相关文章

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

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

  2. HDU 5666 Segment 数论+大数

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  3. HDU 5666 Segment

    Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  4. hdu 4099 Revenge of Fibonacci 字典树+大数

    将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...

  5. HDU 5372 Segment Game

    /** 多校联合2015-muti7-1004 <a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=537 ...

  6. C++大数板子

    C++大数板子 使用样例在主函数里看就好,必要的运算符都重载了. #include <iostream> using namespace std; ;/*精度位数,自行调整*/ //1.如 ...

  7. hdu 5666 (大数乘法) Segment

    题目:这里 题意:在线段x+y=q与坐标轴围成的三角形中,求有多少个坐标为整数的点,答案模上p. 很容易就想到最后答案就是((q-1)*(q-2))/2然后模上p就是了,但是这个数字比较大,相乘会爆l ...

  8. HDU 1042 N!(高精度阶乘、大数乘法)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submi ...

  9. HDU 1402 A * B Problem Plus ——(大数乘法,FFT)

    因为刚学fft,想拿这题练练手,结果WA了个爽= =. 总结几点犯的错误: 1.要注意处理前导零的问题. 2.一定要注意数组大小的问题.(前一个fft的题因为没用到b数组,所以b就没管,这里使用了b数 ...

随机推荐

  1. SDUTOJ2465:其实玩游戏也得学程序(bfs+优先队列+回溯)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2465 题目描述 由于前两次的打击,ZYJ同学不 ...

  2. Py中的多维数组ndarray学习【转载】

    转自:http://blog.sciencenet.cn/home.php?mod=space&uid=3031432&do=blog&id=1064033 1. NumPy中 ...

  3. [LeetCode] 285. Inorder Successor in BST_Medium tag: Inorder Traversal

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...

  4. 用python参加Kaggle的些许经验总结(收藏)

    Step1: Exploratory Data Analysis EDA,也就是对数据进行探索性的分析,一般就用到pandas和matplotlib就够了.EDA一般包括: 每个feature的意义, ...

  5. 批量导入数据到mssql数据库的

    概述 批量导入数据到数据库中,我们有好几种方式. 从一个数据表里生成数据脚本,到另一个数据库里执行脚本 从EXCEL里导入数据 上面两种方式,导入的数据都会生成大量的日志.如果批量导入5W条数据到数据 ...

  6. Linux系统——PXE高效能批量网络装机

    PXE:Pre-boot Excution Environment,预启动执行环境,石油Intel公司开发的网络引导技术,工作在Client.Server模式,允许客户机通过网络从远程服务器下载阴道镜 ...

  7. svn回滚到某一版本

    svn回滚到某一版本 (1)在代码文件夹或vs中show log,查看历史,记住想要回滚到的版本号如1000 (2)新建文件夹,右击svn checkout,在revision中输入版本号1000

  8. MFC六大核心机制之三:动态创建

    MFC中很多地方都使用了动态创建技术.动态创建就是在程序运行时创建指定类的对象.例如MFC的单文档程序中,文档模板类的对象就动态创建了框架窗口对象.文档对象和视图对象.动态创建技术对于希望了解MFC底 ...

  9. C# 将字节流转换为图片的实例方法(转)

    代码如下: usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem. ...

  10. python getctime() 文件最后一次的改变时间

    Return the metadata change time of a file,reported by os.stat() def mm(): file_name=r'c:\temp.txt' f ...