東大卒のお金やりくり奮闘記~株、家計、趣味、経済~

東大卒でメーカー勤務の私がセミリタイアするために投資などを頑張っていこうという趣旨で始めたブログです。既婚男性です。株、家計、趣味、経済の話をメインにゆるゆる話します。

ABC162で書いたコード

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Atcoder20200412
{
    class ProgramA
    {
        static void Main(string args)
        {
            //入力
            string n = Console.ReadLine();

            //どれかの桁が7のときはYes、それ以外はNo
            if(n[0] == '7' || n[1] == '7' || n[2] == '7' )
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }

    class ProgramB
    {
        static void Main(string args)
        {
            
            //入力
            int n = int.Parse(Console.ReadLine());
            long sum = 0;

            //3でも5でも割り切れないときだけ足す
            for(int i = 1;i <= n;i++)
            {
                if(i % 3 != 0 && i % 5 != 0)
                    sum += i;
            }
            
            //答え出力
            Console.WriteLine(sum);
            

        }
    }
 

    class ProgramC
    {
        static void Main(string args)
        {
            
            //入力
            long k = long.Parse(Console.ReadLine());
            long sum = 0;

            
            //i番目の最大公約数を見つける
            for(int i = 1i <= k;i++)
                for(int j = 1j <= k;j++)
                   for(int a = 1a <= k;a++)
                  {
                        long temp = gcd(i,j);//2つの最大公約数を求める
                        temp = gcd(tempa);//前求めた最大公約数と別の一つで求める
                        sum += temp;//求めた最大公約数の和を求める
                    }
            
            //答え出力
            Console.WriteLine(sum);
                
        }

        /*最大公約数を求める関数*/
        static long gcd(long plong q)
        {
            if(p < q)
            {
                long temp = p;
                p = q;
                q = temp;
            }

            long r = 1;

            while(r != 0)
            {
                r = p % q;
                p = q;
                q = r;
            }

            return p;
        }
 
    }  

    class ProgramD
    {
        static void Main(string args)
        {
            
            //入力
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            var r = new List<int>();
            var g = new List<int>();
            int[] b = new int[n];
            long count = 0;

            //RかBかでそれぞれリストを作る
            for(int i = 0;i < n;i++)
            {
                if(s[i] == 'R')
                    r.Add(i+1);
                else if(s[i] == 'G')
                    g.Add(i+1);
                else 
                    b[i] = 1;
            }
            
            //青の数は自然と求める
            int b_num = n - r.Count - g.Count;

            //R,Gのすべての取り方を求める。
            foreach(var a1 in r)
            {
                var x = a1;
                foreach(var a2 in g)
                {
                    var y = a2;
                    
                    //青のすべてのとり方を出す
                    count += b_num;
                    
                    //それぞれ位置に応じて判定する(2y-x-1,(x+y)/2-1,2x-y-1のどれかが省くべきもの)
                    //ただし、それぞれ0からn-1の範囲内で判定する
                    if(2 * y - x -1 >= 0 && 2 * y - x -1 < n)
                        if(b[2 * y - x -1] == 1)
                            count--;
 
                    if((xy) / 2 - 1>= 0 && (xy) / 2 - 1 < n && (x + y) % 2 == 0)
                        if(b[(x + y) /2 -1] == 1)
                            count--;

                    if(2 * x - y - 1 >= 0 && 2 * x - y - 1 < n)
                        if(b[2 * x - y - 1] == 1)
                            count--;   
                }
 
            }
                
            //答え出力
            Console.WriteLine(count);
            

        }
    }
    
}