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. (转)Elasticsearch查询规则------match和term

    es种有两种查询模式,一种是像传递URL参数一样去传递查询语句,被称为简单搜索或查询字符串(query string)搜索,比如 GET /megacorp/employee/_search //查询 ...

  2. (转)Elasticsearch 的坑爹事——记录一次mapping field修改过程

    Elasticsearch 的坑爹事 本文记录一次Elasticsearch mapping field修改过程 团队使用Elasticsearch做日志的分类检索分析服务,使用了类似如下的_mapp ...

  3. (转)HTML5开发中Access-Control-Allow-Origin跨域问题

    今天准备通过JavaScript的方式调用问说问答的内容,由于使用的不同的二级域名,遇到了一个跨域问题,虽然可以使用JSON或者XML来解决这个问题,但是我们可以通过Access-Control-Al ...

  4. Knight Moves(hdu1372 bfs模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Others)   ...

  5. soapUI-JDBC Request

    1.1.1  JDBC Requet 1.1.1.1 概述 – JDBC Request Option Description   JDBC Request TestStep Toolbar 对JDB ...

  6. 透过面试题来说说Promise

    前言 我们先看看这几个来自大厂的面试题 面试题1: const promise = new Promise(function(resolve,reject){ console.log(1) resol ...

  7. JMeter4.0二次开发之导入eclipse

    1.先建立工程,命名为JMeter4.0. JDK版本为10.0.1 2.在官网下载src文件,通过文件系统导入到JMeter4.0工程中 3.在ant中选择download_jars,ant会自动下 ...

  8. Code Blocks+gtest环境配置

    本文仅介绍Code::Blocks+gtest环境配置,gtest具体使用方法请参考: 玩转Google开源C++单元测试框架Google Test系列(gtest)(总) http://www.cn ...

  9. Window下安装npm

    Node.js停火各大技术论坛都在讨论,前段时间工作太忙没时间学习,趁着周末空闲玩玩,在网上找了些资料发现Node.js本身有windows版和unix版下载和使用都挺方便但是其扩展模块依赖复杂通过手 ...

  10. mysql8.0无法给用户授权或提示You are not allowed to create a user with GRANT的问题

    提示意思是不能用grant创建用户,mysql8.0以前的版本可以使用grant在授权的时候隐式的创建用户,8.0以后已经不支持,所以必须先创建用户,然后再授权,命令如下: mysql> CRE ...