http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1035
分析:
这个问题的另一种描述:给定大整数n(可能是质数也可能是合数,且不知道这个数的分解形式),求最小的k使10^k ≡1 (mod n)
1%n=1 这是开始 当10^k ≡1 (mod n)时 这就是结束了 如果没有找不到10^k ≡1 (mod n) 则为1 本题数据量小直接暴力就行 V2
还没做出来
AC代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define gcd(a,b) __gcd(a,b)
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
int n;
int k;
int qpow(int a,int b){
int temp=1;
while (b){
if(b&1)
temp=(temp*a)%k;
b>>=2;a=a*a%k;
}
return temp;
}
int main (){
while (scanf ("%d",&n)!=EOF){
int maxn=-1;int index;
for (k=1;k<=n;k++){
int tt=0;int flag=0;
for (int i=1;i<=k;i++){
if (qpow(10,i)%k==1){
tt=i;flag=1;
break;
}
}
if (!flag) tt=1;
if (maxn<tt){
maxn=tt;
index=k;
}
}
printf ("%d\n",index);
}
return 0;
}