整除个数
时间限制:3000 ms | 内存限制:65535 KB
难度:1
-
描述
- 1、2、3… …n这n(0<n<=1000000000)个数中有多少个数可以被正整数b整除。
-
输入
- 输入包含多组数据
每组数据占一行,每行给出两个正整数n、b。
输出 - 输出每组数据相应的结果。 样例输入
-
2 1 5 3 10 4
样例输出
-
2 1 2
思路:
个数即可用m/n来表示
#include <iostream> //#include <limits.h> #include <string> #include <stdio.h> #include <algorithm> #include <vector> using namespace std; int main() { int m,n; while(cin>>m>>n){ // int a=0; //for(int i=1;i<=m;i++){ // if(i%n==0) // a++; //} cout<<m/n<<endl; } return 0; }
- 输入包含多组数据
本文介绍了一种快速计算从1到n中能被特定整数b整除的数的数量的方法。通过简单的数学公式m/n,避免了遍历计算,极大地提高了效率。
248

被折叠的 条评论
为什么被折叠?



