Comment detail

ダブル完全数 (Nested Flatten)
べたに計算してます。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:my="uri:ja.doukaku.org:my-functions"
  exclude-result-prefixes="my"
  >

  <xsl:output method="text" encoding="sjis" />

  <xsl:template match="/" >
    <xsl:for-each select="1 to 10000">
      <xsl:if test="fn:sum(my:get-divisors(.))=.*2">
        <xsl:value-of select="." />
        <xsl:text> はダブル完全数&#xA;</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  <xsl:function name="my:get-divisors" as="xs:integer*">
    <xsl:param name="n" as="xs:integer" />

    <xsl:if test="$n&gt;1">
      <xsl:for-each select="1 to $n idiv 2">
        <xsl:if test="($n mod .)=0">
          <xsl:sequence select="." />
        </xsl:if>
      </xsl:for-each>
    </xsl:if>
  </xsl:function>

</xsl:stylesheet>

Index

Feed

Other

Link

Pathtraq

loading...