HDU 5666 Segment

规律很简单,画画图就能找出来了。(q-1)*(q-2)/2

裸写乘法longlong会炸,乘法写的优雅一些或者直接用Java能过。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;

long long q,p;

long long Cheng(long long a,long long b)
{
    long long res=0;
    while(b)
    {
        if(b%2==1) res=(res+a)%p,b--;
        a=(a*2)%p,b=b/2;
    }
    return res;
}

int main()
{
    int T; scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&q,&p);
        long long x=q-2,y=q-1; y=y/2;
        printf("%lld\n",Cheng(x,y));
    }
    return 0;
}
时间: 2024-10-16 08:53:11

HDU 5666 Segment的相关文章

HDU - 5666 Segment (大数位运算)好题

HDU - 5666 Segment Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description Silen August does not like to talk with others.She like to find some interesting problems. Today she finds an interesting problem

HDU 5666 Segment——BestCoder Round #80

Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Silen August does not like to talk with others.She like to find some interesting probl

hdu 5666 Segment 俄罗斯乘法或者套大数板子

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 find

hdu 5372 Segment Game(树状数组)

题目链接:hdu 5372 Segment Game 因为线段长度是递增的,不会出现后面的线段被前面的线段完全覆盖,所以只要分别计算[1,l-1]之间有多少个左端点,[1,r]之间有多少个右端点,想减即可. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 2 * 1e5 + 5; #define lowbit(x) ((x)&a

HDU 1558 Segment set (并查集+线段非规范相交)

题目链接 题意 : 如果两个线段相交就属于同一集合,查询某条线段所属集合有多少线段,输出. 思路 : 先判断与其他线段是否相交,然后合并. 1 //1558 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <cmath> 6 #define eps 1e-8 7 #define zero(x) (((x) > 0 ? (x) : (-x)) < e

hdu 5666 (大数乘法) Segment

题目:这里 题意:在线段x+y=q与坐标轴围成的三角形中,求有多少个坐标为整数的点,答案模上p. 很容易就想到最后答案就是((q-1)*(q-2))/2然后模上p就是了,但是这个数字比较大,相乘会爆long long,于是用二进制的乘法,类似于快速幂,另外注意这个除以2得在 之前就处理了,因为最后答案一定要是个准确的整数. 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<

当前插入的线段能完整覆盖存在的几条线段 树状数组 HDU 5372 Segment Game

http://acm.hdu.edu.cn/showproblem.php? pid=5372 Segment Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1284    Accepted Submission(s): 375 Problem Description Lillian is a clever girl so

hdu 1558 Segment set【基础带权并查集+计算几何】

Segment set Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3599    Accepted Submission(s): 1346 Problem Description A segment and all segments which are connected with it compose a segment set

HDU 5666 快速乘

Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 360    Accepted Submission(s): 134 Problem Description Silen August does not like to talk with others.She like to find some interesting pr