首页 > 其他分享 >CodeForces - 597A Divisibility (模拟)

CodeForces - 597A Divisibility (模拟)

时间:2023-05-08 21:31:29浏览次数:48  
标签:Divisibility 597A CodeForces number num 1018 I64d include define

Time Limit: 1000MS

 

Memory Limit: 262144KB

 

64bit IO Format: %I64d & %I64u

CodeForces - 597A


Divisibility



Submit Status




Description




Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.






Input




The only line contains three space-separated integers ka and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).






Output




Print the required number.






Sample Input





Input



1 1 10





Output



10





Input



2 -4 4





Output



5





Source



Testing Round #12



//题意:



给出k,a,b,让你求出在数列a---b之间有多少个数可以整除k.



//思路:



因为数比较大所以不能暴力模拟求解,所以得分情况考虑,主要分三段,



1、b<=0;



2、a<=0,b>=0



3、a>=0



将这三段考虑清楚就可以得出答案了,注意在情况1,3中要对0进行特殊判断。





#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define IN __int64
#define ll long long
#define N 10010
#define M 1000000007
#define PI acos(-1.0)
using namespace std;
int main()
{
	IN k,a,b;
	while(scanf("%I64d%I64d%I64d",&k,&a,&b)!=EOF)
	{
		IN l,r,rr;
		IN num;
		if(a<=0&&b<=0)
		{		
			IN kk=0;	
			if(b%k==0)
				kk=1;
			l=(-a)/k;
			r=(-b)/k;
			num=l-r+kk;
		}
		else if(a<=0&&b>=0)
		{
			l=(-a)/k;
			r=b/k;
			num=l+r+1;
		}
		else if(a>=0&&b>=0)
		{
			IN kk=0;
			if(a%k==0)
				kk=1;
			l=a/k;
			r=b/k;
			num=r-l+kk;
		}
		printf("%I64d\n",num);
	}
	return 0;
}






标签:Divisibility,597A,CodeForces,number,num,1018,I64d,include,define
From: https://blog.51cto.com/u_16079508/6256256

相关文章

  • Codeforces Round 871 (Div. 4)
    A.LoveStory#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintread(){intx=0,f=1,ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory题意:给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。分析:对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可code:#include<bits/stdc++.h>usingnamespacestd;intmain(){ std::ios::sync_wit......
  • Codeforces Round 871 (Div. 4)
    CodeforcesRound871(Div.4)A-LoveStory#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;constintN=1e5+5,INF=0x3f3f3f3f,Mod=1e6;constdoubleeps=1e-6;typedeflonglongll;i......
  • Codeforces 871 div4(重拳出击)
    Codeforces871div4ABC简单题D题意每次操作可以将当前的数分成两份,一份是\(\frac{1}{3}\),一份是\(\frac{2}{3}\),问当前数n可否进行若干次操作,最终出现一份大小为m的片。递归一下就好了,数据最大才\(10^7\)代码voiddfs(intx){ if(x==m){flag=1;return;} if(flag)re......
  • Codeforces Round 870 (Div. 2)
    CodeforcesRound870(Div.2)A-TrustNobody思路:枚举每一种说谎人数x,若a[i]大于x则说谎人数加一,判断最后说谎总人数是否为x,若是则输出x,结束枚举;若没有满足的x则-1#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;......
  • Codeforces 1817F - Entangled Substrings(SA)
    为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?一种SA做法,本质上和SAM做法等价,但是说来也丢人,一般要用到SAM的题我都是拿SA过的/wul考虑将\(ac\)看作一个整体。记\(\text{occ}(S)\)为\(S\)出现位置的集......
  • Codeforces Round 848 (Div. 2)C
    B.TheForbiddenPermutation一定要注意题目中说的是对于alli满足才算不好的,我们做的时候只要破坏一个i这个a就不算好的了,被这一点坑了,没注意到all。#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;constintN=2e5+10;intp[N],a[N];vo......
  • Codeforces Round 856 (Div. 2)C
    C.ScoringSubsequences思路:我们想要找到满足的最大值的长度最长的的区间,因为单调不减,所以更大的数一定在最大值的里面包含,所以我们用两个指针维护这样一个满足当前i的最大值区间,当新来一个数,这时我们答案里面一定要包含这个数,我们看能否保持这个长度,能不能保持需要看j指针所指......
  • Codeforces——870
    A.TrustNobody题目大意给你一个长度为\(n\)的数组\(a\),\(a\)中每个元素\(a_i\)表示当前人认为\(n\)个人中至少有\(a_i\)个人说谎,让你找出说谎的人的个数。思路:枚举说谎人数\(x\),遍历\(a\)数组,对于当前\(a_i\),如果有\(a_i\geqx\),那么显然第\(i\)个人在说谎,记录人数看是否等......
  • [CodeForces-143A]题解(C++)
    PartIPreface原题目(Luogu)原题目(CodeForces)PartIISketch设有一个\(2\times2\)的棋盘,上面可以填入\(1-9\)的数字。给出\(6\)个数字,为每行每列以及每个对角线上的数字之和,求相应的摆放方式,无解输出\(-1\)。PartIIIAnalysis观察此题数据规模,不难发现数据......