Cyclic Number 资料

本文深入探讨了Cyclic Number的概念及其与单位分数之间的联系,详细阐述了如何通过伪代码构造Cyclic Number,并指出在不同进制下的特殊性质。重点介绍了通过计算b进制下的1/p (p为素数)来生成Cyclic Number的方法,同时讨论了完全平方数进制下不存在长度超过1的Cyclic Number的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

全文资料来自wiki:http://en.wikipedia.org/wiki/Cyclic_number

Cyclic number

 Cyclic Number 是一个整数是,且其连续的倍数 (1,2,..,L-1) ,是其本身数字的一个循环。 常见的如下

142857 × 1 = 142857
142857 × 2 = 285714
142857 × 3 = 428571
142857 × 4 = 571428
142857 × 5 = 714285
142857 × 6 = 857142

而形如下非连续的倍数不是

076923 × 1 = 076923
076923 × 3 = 230769
076923 × 4 = 307692
076923 × 9 = 692307
076923 × 10 = 769230
076923 × 12 = 923076

若不允许前导0,则十进制下,仅有一个Cyclic Number, 142857

相关重复小数

Cyclic Number与单位分数(其小数形式重复片段)相关,长度为L的Cyclic Number可以表现为一下形式: 1 / (L+1)

相反的,如果 1/p (p是质数)  的重复片段是 p-1, 那么这个数字 p-1,就代表着一个 Cyclic Number.

例如   1/7 = 0.142857 142857….  其连续倍数如下:

1/7 = 0.142857 1428572/7 = 0.285714 2857143/7 = 0.428571 4285714/7 = 0.571428 5714285/7 = 0.714285 7142856/7 = 0.857142 857142….

Cyclic Number的形式 

  从上面单位分数形式,得到如下形式: \frac{b^{p-1}-1}{p}       其中b是进制,p是素数,且 b%p != 0 .

  不是所有的素数p都能通过以上形式产生 Cyclic Number, 例如 p=13 gives 076923076923, 会出现多个循环。

构造Cyclic Number 

伪代码如下:

Let b be the number base (10 for decimal)
Let p be a prime that does not divide b.
Let t = 0.
Let r = 1.
Let n = 0.
loop:
Let t = t + 1
Let x = r · b
Let d = int(x / p)
Let r = x mod p
Let n = n · b + d
If r ≠ 1 then repeat the loop.
if t = p − 1 then n is a cyclic number.

此程序是通过计算 b进制下的Cyclic Number  1/p . 其中r是每一步的剩余系,d是当前步的产生数,当前值为 n = n*b + d.

注意,若 t > p/2, 则这个数必定为 Cyclic Number, 无需继续计算后面部分了。

当 b 为完全平方数时,不存在长度超过1的Cyclic Number.

 

推荐训练题: http://www.codeforces.com/problemset/problem/303/D

用以上方法写的代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

bool IsPrime(int x){
    for(int i = 2; i*i <= x; i++)
        if(x%i == 0) return false;
    return true;
}
int main(){
    int L, x, p;
    scanf("%d%d", &L, &x);
    p = L+1;
    if( (x == 2) || !IsPrime(p) ){
        puts("-1"); return 0;        
    }
    for(int b = x-1; b > 1; b--){
        if( b%p == 0 ) continue;
        LL t = 0, r = 1, n = 0, x, d;
        while(1){
            t = t+1; x = r*b; d = x/p; r = x%p; 
            n = n*b + d;
            if( r == 1 ) break;
            if( t > p/2 ){ printf("%d\n",b); return 0; }    
        }
        if( t == L ){ printf("%d\n",b);return 0; }    
    }        
    puts("-1");    
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/yefeng1627/archive/2013/05/14/3077399.html

/**************************** Type Definitions *******************************/ /** Container structure for descriptor storage control. If address translation * is enabled, then all addresses and pointers excluding FirstBdPhysAddr are * expressed in terms of the virtual address. */ typedef struct { UINTPTR ChanBase; /**< physical base address*/ int IsRxChannel; /**< Is this a receive channel */ volatile int RunState; /**< Whether channel is running */ int HasStsCntrlStrm; /**< Whether has stscntrl stream */ int HasDRE; int DataWidth; int Addr_ext; u32 MaxTransferLen; UINTPTR FirstBdPhysAddr; /**< Physical address of 1st BD in list */ UINTPTR FirstBdAddr; /**< Virtual address of 1st BD in list */ UINTPTR LastBdAddr; /**< Virtual address of last BD in the list */ u32 Length; /**< Total size of ring in bytes */ UINTPTR Separation; /**< Number of bytes between the starting address of adjacent BDs */ XAxiDma_Bd *FreeHead; /**< First BD in the free group */ XAxiDma_Bd *PreHead; /**< First BD in the pre-work group */ XAxiDma_Bd *HwHead; /**< First BD in the work group */ XAxiDma_Bd *HwTail; /**< Last BD in the work group */ XAxiDma_Bd *PostHead; /**< First BD in the post-work group */ XAxiDma_Bd *BdaRestart; /**< BD to load when channel is started */ XAxiDma_Bd *CyclicBd; /**< Useful for Cyclic DMA operations */ int FreeCnt; /**< Number of allocatable BDs in free group */ int PreCnt; /**< Number of BDs in pre-work group */ int HwCnt; /**< Number of BDs in work group */ int PostCnt; /**< Number of BDs in post-work group */ int AllCnt; /**< Total Number of BDs for channel */ int RingIndex; /**< Ring Index */ int Cyclic; /**< Check for cyclic DMA Mode */ } XAxiDma_BdRing;
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值