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).
题目大意:给出一个整数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 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步