Source Code

for file S01_AsyncSamples/CalcFactorsRequest.aspx

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>

<script runat="server">

  private string CalcPrimeFactors(string inputText) {
    string outputText = String.Empty;
    UInt64 prime;  // try this factor (only primes will match!)
    UInt64 number; // product of the remaining factors

    if ((inputText == null) || (inputText.Length == 0) || (inputText == "0"))
      return("no number given.");

    prime = 2; // start with 2
    number = UInt64.Parse(inputText);

    while ((number > 1) && (prime * prime <= number)) {
      if (number % prime != 0) {
        // try the next factor (slowly)
        prime += 1;

      } else {
        // found a factor !
        outputText = outputText + " " + prime;
        number = number / prime;
      } // if
    } // while

    if (number > 1) {
      // the last factor (a prime) is here.
      outputText = outputText + " " + number;
    }

    return(outputText.Trim());

  } // CalcPrimeFactors
  
</script>
<%
  Response.Clear();
  string ret = CalcPrimeFactors(Request.QueryString["number"]);
  Response.Write(ret);
%>

This page is part of the http://www.mathertel.de/ web site.

For updates and discussions see http://ajaxaspects.blogspot.com/.