关闭

她 she

136人阅读 评论(0) 收藏 举报
分类:

这里写图片描述
30% 暴力枚举
另外20% 拓展欧几里得

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL L,R,m,s,p;
int T;
LL ex_gcd(LL a,LL b,LL &x,LL &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    LL ans=ex_gcd(b,a%b,x,y);
    LL xx=x;
    x=y;
    y=xx-a/b*y;
    return ans;
}
void work()
{
    scanf("%lld%lld%lld%lld",&m,&s,&L,&R);
    if(L>R||s%m==0||L>m) {printf("-1\n");return;} 
    if(L==R)
    {
        LL x,y;
        p=ex_gcd(s,m,x,y);
        if(R%p) {printf("-1\n");return;} 

        m=m/p;
        printf("%lld\n",(x*L/p%m+m)%m);
        return;
    }
    else
    {
        for(LL x=1;x;x++)
        {
            if(s*x%m<=R&&s*x%m>=L) 
            {
                printf("%lld\n",x);
                return;
            }
        }
    }
}
int main()
{
    freopen("she.in","r",stdin);
    freopen("she.out","w",stdout);
    scanf("%d",&T);
    while(T--) work();
    return 0;
}
0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

杭电OJ——1033 Edge

Edge Problem Description For products that are wrapped in small packings it is necessary tha...
  • lishuhuakai
  • lishuhuakai
  • 2013-07-07 14:43
  • 2283

hdu4614Vases and Flowers(线段树,段设置,更新时范围的右边值为变量)

Problem Description   Alice is so popular that she can receive many flowers everyday. She has N vas...
  • u010372095
  • u010372095
  • 2013-10-13 18:22
  • 1378

Linux Shell之脚本的执行

Linux的命令分为两类:一类是shell的内建命令;另一类则是独立于shell的命令。别忘了,shell也只是系统中的一个程序而已,当它执行非内建命令时,本质上是在呼叫另一只程序,比如ls。 "#!...
  • u012668018
  • u012668018
  • 2015-06-24 23:33
  • 1332

[USACO 2014 Jan Bronze]滑雪训练课程题解

觉得自己真是越来越堕落了。。开始做
  • wuzhuangtai00
  • wuzhuangtai00
  • 2014-10-19 15:08
  • 597

SDNU 1141.Greatest Number【山东省第一届ACM】【7月22】

Greatest Number Description Saya likes math, because she think math can make her clevere...
  • a995549572
  • a995549572
  • 2015-07-22 20:54
  • 418

2014多校3(1002)hdu4888(最大流(dinic))

Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja...
  • cq_phqg
  • cq_phqg
  • 2014-08-11 19:24
  • 580

hdu 1669 Jamie's Contact Groups(二分+二分图最大多重匹配)

Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/...
  • acm_cxq
  • acm_cxq
  • 2016-07-28 10:18
  • 212

学英语《每日一歌》之she

【每日一歌】今天给大家推荐的是Groove Coverage(舞动精灵王族)的一首经典老歌-《she》。Groove Coverage在中国最出名的歌曲莫过于God Is A Girl,Far A...
  • erlian1992
  • erlian1992
  • 2015-04-20 22:39
  • 851

【USACO16OPEN】248 动态规划

题目描述Bessie likes downloading games to play on her cell phone, even though she doesfind the small tou...
  • zhhe0101
  • zhhe0101
  • 2016-11-16 21:57
  • 195

POJ 题目2761 Feed the dogs(主席树||划分树)

Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 16860   ...
  • yu_ch_sh
  • yu_ch_sh
  • 2015-08-23 20:58
  • 800
    个人资料
    • 访问:39768次
    • 积分:3832
    • 等级:
    • 排名:第9666名
    • 原创:340篇
    • 转载:1篇
    • 译文:0篇
    • 评论:6条
    友链
    文章分类
    最新评论