首页 > 其他分享 >【MX-J1-T2】『FLA - III』Ilumina 题解

【MX-J1-T2】『FLA - III』Ilumina 题解

时间:2024-07-14 20:31:22浏览次数:11  
标签:lfloor le frac cout 所以 题解 T2 J1 nx

题目传送门

【MX-J1-T2】『FLA - III』Ilumina

思路

硬导题。

因为 \(c=\lfloor \frac{b}{m}\rfloor\),那么 \(b\) 一定可以表示为 \(c\times m+x\),其中 \(0\le x\le m-1\)。

又因为 \(b=\lfloor \frac{a}{n}\rfloor\),那么 \(a\) 一定可以表示为 \(b\times n+y\),其中 \(0\le y\le n-1\)。

由上可以得出:

\[b=cm+x \]

\[a=bn+y \]

所以:

\[b=\frac{a-y}{n} \]

所以:

\[\frac{a-y}{n}=cm+x \]

\[\therefore a=cmn+nx+y \]

由于 \(a,c,m,n,x,y\in N\) 且 \(m\) 和 \(n\) 不为 \(0\),所以 \(a\ge c\)。

考虑分类讨论:

  • \(a<c\) 时:因为若有解,那么 \(a\) 一定不小于 \(c\),所以此时无解。

  • \(a=c\) 时:很容易可以得出当 \(m=n=1\) 时,一定满足 \(a=b=c\),所以一个合法 \(b\) 的值就等于 \(a\) 和 \(c\)。

  • \(a>c\) 时:重新考虑上述方程,即 \(a=cmn+nx+y\):因为 \(x\le m-1,y\le n-1\),所以 \(nx+y\le n(m-1)+n-1\),所以 \(nx+y\le mn-1\),所以再设 \(z=nx+y\),所以 \(0\le z\le mn-1\),代入方程,可得: \(a=cmn+z\),再令 \(mn=f\),所以 \(a=cf+z\),其中 \(0\le z\le f-1\)。此时我们只需要考虑 \(f\) 存不存在正整数解即可。

(判断 \(f\) 有没有正整数解很简单,用贪心的思想,我们可以要求 \(f\) 尽可能大,也就是让 \(f=\lfloor\frac{a}{c}\rfloor\),然后判断 \(a-cf\) 与 \(f\) 的大小即可,具体见代码。)

代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--){
		int a,c;cin>>a>>c;
		if(a==c)cout<<a<<endl;
		else if(a<c)cout<<-1<<endl;
		else{
			int f=a/c;int u=a-c*f;
			if(u>=f)cout<<-1<<endl;
			else cout<<c<<endl;
		}
	}
	return 0;
}

标签:lfloor,le,frac,cout,所以,题解,T2,J1,nx
From: https://www.cnblogs.com/snapyust/p/18301962

相关文章

  • 题解:P10765 「CROI · R2」在相思树下 I
    在发布求救信号后,@我就在这里253发了题解。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintt,ans;voidsolve(){ intn,k,x,ans; scanf("%lld%lld",&n,&k); ans=1; intpre=1,behind=n; for(inti=0;i<k;i++......
  • 题解 P1007 独木桥
    link题意\(N\)个人在长度为\(L\)独木桥上走动,桥上的坐标为\(1,2,\cdots,L\),你不知道他们的方向。他们的速度都为\(1\)。当两个人相遇时,他们就分别转身,继续行走。(转身不花费时间)当某人来到\(0\)或\(L+1\)的位置,他就离开了独木桥。给定\(N\)、\(L\)和\(......
  • 2021杭电多校10 D.Pty hates prime numbers题解
    前言暑期第三次组队赛是选的21年杭电多校10,遗憾爆0,被对面队打爆,赛后狠狠补题。这道题的题解,以及网上搜到的其他题解看了好久没看懂,在问了队里大腿多次后,总算磨出来了,这里讲一下我的理解。题意多次询问,每次给定\(n\)和\(k\),如果一个数的质因数里包括前\(k\)个质数,则这个数......
  • NSIS 之 NsDialogs 常见问题解答
    如何启用/禁用控件使用标准NSIS EnableWindow 命令。NSDialogs允许您弹出通过 ${NSD_Create*} 创建的控件的 hwnd (句柄)。EnableWindow 将 hwnd 作为其参数之一。通过它,您可以轻松启用/禁用控件。  !include"nsDialogs.nsh"!include"winmessages.nsh"!incl......
  • 题解:AT_abc362_d [ABC362D] Shortest Path 3
    一句话题意:给定一个带点权的有权无向连通图,求点1到所有其它点的最短路径。首先,只有1一个起点,所以是单源最短路,又因为最大是\(2\times10^5\),所以是优先队列(堆)优化过后的Dijkstra。所以,我们只需要解决点权的问题就好了。一种显而易见的想法是把与这条边的边权加上起终点......
  • 题解:CodeForces 346A Alice and Bob[博弈/数论]
    CodeForces346AA.AliceandBobtimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputItissoboringinthesummerholiday,isn'tit?SoAliceandBobhaveinventedanewgametoplay.Therulesa......
  • 题解:CodeForces 843A Sorting by Subsequences[模拟/排序]
    CodeForces843AA.SortingbySubsequencestimelimitpertest:1secondmemorylimitpertest:256megabytesinputstandardinputoutputstandardoutputYouaregivenasequence\(a_1, a_2, ..., a_n\)consistingofdifferentintegers.Itisrequiredtos......
  • 题解:CodeForces 618C Constellation[贪心/模拟]
    CodeForces618CC.Constellationtimelimitpertest:2secondsmemorylimitpertest:256megabytesinputstandardinputoutputstandardoutputCatNokuhasobtainedamapofthenightsky.Onthismap,hefoundaconstellationwithnstarsnumberedfrom......
  • 题解:CodeForces 835 D Palindromic characteristics[区间dp/马拉车Manacher]
    CodeForces835DD.Palindromiccharacteristicstimelimitpertest:3secondsmemorylimitpertest:256megabytes*inputstandardinputoutputstandardoutputPalindromiccharacteristicsofstring\(s\)withlength\(|s|\)isasequenceof\(|s|\)in......
  • 题解:CodeForces 1019 A Elections[贪心/三分]
    CodeForces1019AA.Electionstimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputAsyouknow,majorityofstudentsandteachersofSummerInformaticsSchoolliveinBerlandforthemostparto......