1/6= 0.1(6) 循环节长度为1
1/7= 0.(142857) 循环节长度为6
1/9= 0.(1) 循环节长度为1
10
7
先打表打出1-1000每个数循环节循环节判断方法是如果 新余数 在之前的余数出现过 那么一定是有循环节 注意避免初始余数的操作
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
long long t;
long long n, a, b;
long long gcd(long long x, long long y)
{
return y == 0 ? x : gcd(y, x%y);
}
long long extgcd(long long a, long long b, long long &x, long long &y)
{
if (b == 0)
{
x = 1;y = 0;
return a;
}
long long r = extgcd(b, a%b, x, y);
long long t = x;
x = y;
y = t - a / b*y;
return r;
}
int ans[1010] = {0};
int main()
{
ans[1] = 0;
for (int i = 2;i < 1001;i++)
{
int vis[1010] = { 0 };
int s = 1;
int key = 1;
while (s != 0)
{
if (vis[s] != 0)
{
ans[i] = key - vis[s];
break;
}
vis[s] = key++;
s = (s * 10) % i;
}
//ans[i] = max(ans[i - 1], ans[i]);
}
int n;
scanf("%d", &n);
int maxloc = 1;
for (int i = 1;i <= n;i++)
{
if (ans[i] >= ans[maxloc])
maxloc = i;
}
printf("%d\n", maxloc);
return 0;
}
本文详细解析51nod在线判题系统中的第1035题,该题目涉及简单数论概念,主要探讨如何找出一个整数的最长循环节。通过深入理解数论原理,结合编程技巧,解决这个问题,并给出高效算法实现。


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



