hdu 5666 Segment 俄罗斯乘法或者套大数板子
Segment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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.
Then,each line has two integers q,P.
q is a prime number,and 2≤q≤1018,1≤P≤1018,1≤T≤10.
2 107
#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 俄罗斯乘法或者套大数板子的更多相关文章
- hdu-5666 Segment(俄罗斯乘法or大数乘法取模)
题目链接: Segment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) P ...
- HDU 5666 Segment 数论+大数
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- HDU 5666 Segment
Segment Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdu 4099 Revenge of Fibonacci 字典树+大数
将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...
- HDU 5372 Segment Game
/** 多校联合2015-muti7-1004 <a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=537 ...
- C++大数板子
C++大数板子 使用样例在主函数里看就好,必要的运算符都重载了. #include <iostream> using namespace std; ;/*精度位数,自行调整*/ //1.如 ...
- hdu 5666 (大数乘法) Segment
题目:这里 题意:在线段x+y=q与坐标轴围成的三角形中,求有多少个坐标为整数的点,答案模上p. 很容易就想到最后答案就是((q-1)*(q-2))/2然后模上p就是了,但是这个数字比较大,相乘会爆l ...
- HDU 1042 N!(高精度阶乘、大数乘法)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submi ...
- HDU 1402 A * B Problem Plus ——(大数乘法,FFT)
因为刚学fft,想拿这题练练手,结果WA了个爽= =. 总结几点犯的错误: 1.要注意处理前导零的问题. 2.一定要注意数组大小的问题.(前一个fft的题因为没用到b数组,所以b就没管,这里使用了b数 ...
随机推荐
- Kylin构建cube时状态一直处于pending
在安装好kylin之后我直接去访问web监控页面发现能够进去,也没有去看日志.然后在运行官方带的例子去bulid cube时去发现状态一直是pending而不是runing.这个时候才去查看日志: 2 ...
- Qt5
最简单的分割窗体 #include <QApplication> #include <QLabel> #include <QSplitter> int main(i ...
- QPixmap 显示大小
size picSize(600,400); //将pixmap缩放成picSize大小然后保存在scaledPixmap中 按比例缩放: QPixmap scaledPixmap = pixmap. ...
- JSON—序列化
表单数据的序列化 用SerializeArray()将有效控件序列化为JSON对象数组? 包含name和value两个属性 SerializeArray()检测一组表单元素中的有效控件? 1.没有 ...
- jquery ajax基本用法
<script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script> <s ...
- AdaBoost学习笔记
学习了李航<统计学习方法>第八章的提升方法,现在对常用的一种提升方法AdaBoost作一个小小的笔记,并用python实现书本上的例子,加深印象.提升方法(boosting)是一种常用的统 ...
- 实现kylin定时跑当天的任务
说明: 每天自动构建cube,动态在superset里面查看每天曲线变化图 #! /bin/bash ##cubeName cube的名称 ##endTime 执行build cube的结束时间 (命 ...
- Python3 简明教程
Python是由吉多·范罗苏姆(Guido Van Rossum)在90年代早期设计.它是如今最常用的编程 语言之一.它的语法简洁且优美,几乎就是可执行的伪代码. 注意:这篇教程是特别为Python3 ...
- 下载及安装selenium IDE
安装方法1:可以从官方网站下载:http://seleniumhq.org/download/,但是由于selenium服务器在美国,中美的网络经常不稳定,经常会连接失败,导致下载不了 可以找一下se ...
- 使用 Laravel 数据填充生成 中文 测试数据
Laravel5.4 及更新版本设置了相关的配置项 app.faker_locale,只不过在文档和默认的配置文件中看不到这一参数.相关源码在 Illuminate\Database\Database ...