整除个数(水题)

整除个数

时间限制: 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

整除个数就是n/b,n里面有多少个b,即b*1,b*2,b*3.....都能被b整除,就是看n里面含有多少个整个的b。

还以为是用同余定理。。。

代码(注释部分是一开始用同余定理写的,时间超限):

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    long n,b;
    while(~scanf("%ld%ld",&n,&b))
    {
//        int i=0;
//        while((b+i*b<=n))
//              i++;
//        printf("%d\n",i);
          printf("%d\n",n/b);
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/nanfengzhiwoxin/article/details/80171323
今日推荐