using System;
class Program
{
private static int GetThird(int num)
var result = 0;
var kv = num * num;
if (num % 2 == 0)
for (var i = num / 2; i > 0; i--)
result += kv - i * 2 + 1;
}
for (var i = 0; i < num / 2; i++)
result += kv + i * 2 + 1;
else
for (var i = (num - 1) / 2; i > 0; i--)
result += kv - i * 2;
result += kv;
for (var i = 0; i < (num - 1) / 2; i++)
result += kv + i * 2 + 2;
return result;
//оптимизированное свое решение, коротко и ясно
private static int GetThirdOptimized(int num)
var kv = num * num - num + 1;
for (var i = 0; i < num; i++)
result += kv + i * 2;
private static void Main()
Console.WriteLine("Введите натуральноe числo ");
var i = int.Parse(Console.ReadLine());
Console.WriteLine("{0}^3 = {1} = {2} = {3}", i, i * i * i, GetThird(i), GetThirdOptimized(i));
Console.Read();
program raf105;
uses robot;
begin
task('if5');
if (wallfromdown) or (wallfromup)
then begin left; paint; right; right; paint; left;
end;
if (wallfromleft) or (wallfromright)
then begin up; paint; down; down; paint; up;
end.
task('if6');
up;
if cellispainted
then begin down; down; paint; end
else begin down; down;
then begin up; up; paint; end
else begin up; left;
then begin right; right; paint; end
else paint;
task('if7');
if wallfromright and wallfromdown
then begin up; left; paint; end;
if wallfromleft and wallfromdown
then begin up; right; paint; end;
if wallfromup and wallfromleft
then begin right; down; paint; end;
if wallfromup and wallfromright
then begin down; left; paint; end
using System;
class Program
{
private static int GetThird(int num)
{
var result = 0;
var kv = num * num;
if (num % 2 == 0)
{
for (var i = num / 2; i > 0; i--)
{
result += kv - i * 2 + 1;
}
for (var i = 0; i < num / 2; i++)
{
result += kv + i * 2 + 1;
}
}
else
{
for (var i = (num - 1) / 2; i > 0; i--)
{
result += kv - i * 2;
}
result += kv;
for (var i = 0; i < (num - 1) / 2; i++)
{
result += kv + i * 2 + 2;
}
}
return result;
}
//оптимизированное свое решение, коротко и ясно
private static int GetThirdOptimized(int num)
{
var result = 0;
var kv = num * num - num + 1;
for (var i = 0; i < num; i++)
{
result += kv + i * 2;
}
return result;
}
private static void Main()
{
Console.WriteLine("Введите натуральноe числo ");
var i = int.Parse(Console.ReadLine());
Console.WriteLine("{0}^3 = {1} = {2} = {3}", i, i * i * i, GetThird(i), GetThirdOptimized(i));
Console.Read();
}
}
program raf105;
uses robot;
begin
task('if5');
if (wallfromdown) or (wallfromup)
then begin left; paint; right; right; paint; left;
end;
if (wallfromleft) or (wallfromright)
then begin up; paint; down; down; paint; up;
end;
end.
if6program raf105;
uses robot;
begin
task('if6');
up;
if cellispainted
then begin down; down; paint; end
else begin down; down;
if cellispainted
then begin up; up; paint; end
else begin up; left;
if cellispainted
then begin right; right; paint; end
else paint;
end;
end;
end.
if7program raf105;
uses robot;
begin
task('if7');
if wallfromright and wallfromdown
then begin up; left; paint; end;
if wallfromleft and wallfromdown
then begin up; right; paint; end;
if wallfromup and wallfromleft
then begin right; down; paint; end;
if wallfromup and wallfromright
then begin down; left; paint; end
end.