51Nod 1035 最长的循环节
来源:互联网 发布:李谷一 知乎 编辑:程序博客网 时间:2024/06/05 04:10
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;}
阅读全文
0 0
- 51nod 1035:最长的循环节
- 51nod 1035 最长的循环节
- 51NOD 1035 最长的循环节
- 51nod 1035 最长的循环节
- 51nod-【1035 最长的循环节】
- 51Nod 1035 最长的循环节
- 51nod 1035 最长的循环节
- 【51Nod】1035 最长的循环节
- 51nod 1035 最长的循环节
- 51nod 1035 最长的循环节
- 51Nod 1035 最长的循环节
- 51nod oj 1035 最长的循环节 【循环】
- [51Nod 1035 最长的循环节] 循环小数的性质
- 51Nod-点头网-1035 最长的循环节
- 51NOD 1035 最长的循环节(数论)
- 51Nod-1035-最长的循环节
- 51nod - 1035 最长的循环节 - 数论
- 51nod oj 1035 最长的循环节 简单数论
- 蒟蒻复习之-----Tarjan
- 在Linux下安装MySQL
- 文章获取与单词统计排序
- [bzoj4552][Tjoi2016&Heoi2016]排序 二分+线段树
- 河城荷取 二分答案 最大流
- 51Nod 1035 最长的循环节
- [java]创建新数组的三种方式
- 字符串的连接
- HBase之——Shell基础操作
- LeetCode 328. Odd Even Linked List
- 设置坐标轴长度和范围
- python的MySQL操作增删改查
- VS2017开发Windows服务
- java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView