为了能到远方,脚下的每一步都不能少.|

smiling&weeping

园龄:1年8个月粉丝:2关注:0

Longest Divisors Interval

Smiling & Weeping

                    ----总有一个人,

                      一直住在心底,

                      却消失在生活里。

Given a positive integer n, find the maximum size of an interval [l,r] of positive integers such that, for every in the interval (i.e., l≤i≤r), n is a multiple of i.

Given two integers l≤r, the size of the interval [l,r] is r−l+1 (i.e., it coincides with the number of integers belonging to the interval).

题目链接:Problem - B - Codeforces

题目大意:给出一个整数n,求一个区间(要求区间连续,且每个整数都能整除n)

思路:当时这个题目感觉很奇怪,不难但是不好想,例如,若n不能被3整除,那么一定不能被三的倍数整除(也就是说每取出三个连续的数,必有一个不能不符合题意),那么我们就好想通了,直接求从1-n,最多能被多少个连续的数字整除。

Input:

10
1
40
990990
4204474560
169958913706572972
365988220345828080
387701719537826430
620196883578129853
864802341280805662
1000000000000000000

Output:

1
2
3
6
4
22
3
1
2
2

现在是代码时间 ̄へ ̄:Show me Your Code

复制代码
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int t;
 4 typedef long long ll;
 5 int main()
 6 {
 7     scanf("%d",&t);
 8     while(t--)
 9     {
10         int i = 1;
11         ll num , cnt = 0;
12         scanf("%lld",&num);
13         while(num%i == 0) i++ , cnt++;
14         printf("%lld\n",cnt);
15     }
16     return 0;
17 }
复制代码

文章到此结束,我们下次再见ヾ( ̄▽ ̄)Bye~Bye~

本文作者:Smiling-Weeping

本文链接:https://www.cnblogs.com/smiling-weeping-zhr/p/17595311.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   smiling&weeping  阅读(50)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起