python3--这种题,只想说呵呵,有意思么 a,b,c=map(int,input().split()) if a%c==0: print((b-a)//c+1) else: print((b-(a//c+1)*c)//c+1)
#include <iostream> //#include <string> //#include <vector> using namespace std; int Countnum(int a, int b, int c) { int ans=0; if(a%c==0) ans++; if(b%c==0) ans++; a++; b--; if(b%c==0) ans++; int tmp=b-a; ans+=tmp/c; return ans; } int main() { int a,b,c; cin>>a>>b>>c; cout<<Countnum(a,b,c); return 0; }
分析:调整a到一个可以被c整除的位置,然后以c为步长计算就好了importjava.util.Scanner;//在[a, b]区间内找到一些数满足可以被一个整数c整除,publicclassMain {publicstaticvoidmain(String[] args){Scanner in = newScanner(System.in);while(in.hasNext()){intbegin = in.nextInt();intend = in.nextInt();intnum = in.nextInt();//int count = 0;//for(int i = begin; i <= end; i++){// if(i % num == 0){// count++;//}//}//System.out.println(count);while(begin % num != 0){begin++;}if(begin > end){System.out.println(0);}else{System.out.println((end - begin) / num + 1);}}}}
import java.util.Scanner; public class Main { public static void main(String [] args){ Scanner scanner = new Scanner(System.in); int min=scanner.nextInt(); int max=scanner.nextInt(); int div=scanner.nextInt(); int count=0; //for(int i=min;i<=max;i++){ // if(i%div==0){ // count=(max-i)/div+1; // break; // } //} int b=min; while(b<=max){ if(b%div==0){ count=(max-b)/div+1; break; } b++; } System.out.println(count); scanner.close(); } }
#include<iostream> using namespace std; int find(int a, int b, int c) { if (b <= 0) return find(-1 * b, -1 * a, c); else { if (a < 0) return find(0, b, c) + find(1, -1 * a, c); else { int result = 0; if (a == 0 || (a%c == 0 && b%c == 0)) result++; if (c > b) return result; int tmp1 = a / c; int tmp2 = b / c; result += tmp2 - tmp1; return result; } } } int main() { int a, b, c; cin >> a >> b >> c; cout << find(a, b, c); return 0; }
}
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> int main(){ using namespace std; int a, b, c; while(cin >> a >> b >> c){ int ans = 0; int first; if(a % c) first = c - a % c + a; else first = a; for(int i = first; i <= b; i = i + c) ans ++; cout << ans << endl; } return 0; }
#include<iostream>
using namespace std;
void getExactDivision(long long int a, long long int b, long int c)
{
int num_an = 0;
int num_bn = 0;
num_bn = b / c;//求出倍数
num_an = a / c;
if (a != 0)//判断是否为0
{
if (b / a < 0)//说明 异号
{
cout << (num_bn - num_an + 1) << endl;
}
else
cout << (num_bn - num_an) << endl;;
}
else if (a == 0)
{//等于0
cout << (num_bn - num_an + 1) << endl;
}
}
int main()
{
long long int min_an, max_bn;
cin >> min_an >> max_bn;//输入范围
long int num_cn;
cin >> num_cn;
//输入c
getExactDivision(min_an, max_bn, num_cn);
return 0;
}
#include <iostream> using namespace std; int main() { int n1, n2,n3; int count = 0; cin >> n1 >> n2 >> n3; if (n1 < 0 && n2 < 0) count = n2 / n3 - n1 / n3; if (n1 <= 0&&n2>=0) count = n2 / n3 - n1 / n3 + 1; if (n1 > 0 && n2 > 0) count = n2 / n3 - n1 / n3; cout << count; return 0; }