This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program { | |
static void Main(string[] args) { | |
Console.WriteLine(Gcd(0, 8)); | |
Console.WriteLine(Gcd(12, 8)); | |
Console.WriteLine(Gcd(3400, 6596)); | |
Console.WriteLine(Gcd(12707, 12319)); | |
} | |
// ユークリッドの互除法 | |
public static int Gcd(int a, int b) { | |
if (a < b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long Fibo(int n) { | |
if (n == 0) | |
return 0; | |
if (n == 1) | |
return 1; | |
return Fibo(n - 1) + Fibo(n - 2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace Gushwell.Etude { | |
class Program { | |
static void Main(string[] args) { | |
// 1 - 100 までのメビウス関数を求める | |
int upper = 100; | |
Mebius mebius = new Mebius(upper); | |
for (int i = 1; i <= upper; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 下限、上限が指定できるbool型配列 | |
class BoundedBoolArray { | |
private BitArray _array; | |
private int _lower; | |
public BoundedBoolArray(int lower, int upper) { | |
_array = new BitArray(upper - lower + 1); | |
_lower = lower; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static IEnumerable<int> Primes(int maxnum) { | |
// var sieve = new BitArray(maxnum + 1, true); | |
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); | |
int squareroot = (int)Math.Sqrt(maxnum); | |
for (int i = 2; i <= squareroot; i++) { | |
if (sieve[i] == false) | |
continue; | |
for (int n = i * 2; n <= maxnum; n += i) | |
sieve[n] = false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long Factorial(int n) { | |
if (n == 0) | |
return 1L; | |
return n * Factorial(n - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows; | |
using System.Windows.Media.Imaging; | |
namespace DataTemplateSample { | |
public partial class MainWindow : Window { | |
public MainWindow() { | |
InitializeComponent(); | |
} | |
private void Window_Loaded(object sender, RoutedEventArgs e) { | |
MyImage mi = new MyImage(); |