Skip to content

Instantly share code, notes, and snippets.

@kuuso
Created May 9, 2016 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuuso/e4eafbd271bdf228d0b91e2a278247a4 to your computer and use it in GitHub Desktop.
Save kuuso/e4eafbd271bdf228d0b91e2a278247a4 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
/*
// sample
Check(F(30,50,40,40),30000000);
Check(F(20,60,50,20),50000000);
Check(F(45,40,10,95),4515341);
Check(F(70,30,50,50),62122012);
Check(F(30,50,90,15),133176131);
Check(G(13),27);
Check(G(100),155);
Check(G(102),101);
Check(G(30031),96767);
Check(G(62122012),101219327);
Check(H(20),56);
Check(H(100),540);
Check(H(10000),545040);
Check(H(987789),533115672);
Check(H(101219327),557319321362 );
Check(H( G( F(70, 30, 50, 50) ) ),557319321362 );
Check(H( G( F(50, 30, 70, 20) ) ),932689603284 );
Check(H( G( F(2, 2, 173, 3) ) ),1424505244250 );
Check(H( G( F(2, 2, 173, 4) ) ),54361133355 );
*/
var Input=ria();
Console.WriteLine(H(G(F(Input[0], Input[1], Input[2], Input[3]))));
}
static bool Check(long input, long ans){
Console.Write(input==ans?"OK":"NG");
if(input!=ans){
Console.Write(": input={0},ans={1}",input,ans);
}
Console.WriteLine();
return input==ans;
}
public Sol(){
}
static long F(int a,int b,int c,int d){
// 辺の長さを決めると形状が確定するので、BC=1として計算する
double pi=Math.PI;
double BD=Math.Sin(pi*(c+d)/180.0)/Math.Sin(pi*(180-b-c-d)/180.0);
double AB=Math.Sin(pi*c/180.0)/Math.Sin(pi*(180-a-b-c)/180.0);
double AD2=AB*AB+BD*BD-2*AB*BD*Math.Cos(pi*a/180.0);
double AD=Math.Sqrt(AD2);
double cosx=(AB*AB-BD*BD-AD2)/(-2.0*AD*BD);
double x=Math.Acos(cosx)*180/pi;
// 誤差回避
double eps=1e-9;
return (long)((x+eps)*1000000);
}
static long G(long n){
// n%d == 1 なる d の総和
//=> ∃ k, n = dk + 1 (d>1)
//=> ∃ k, s.t. (n-1) = dk (d>1)
//=> d:(n-1)の約数 かつ 1より大
n--;
long sum=0;
for(long j=1;j*j<=n;j++){
if(n%j!=0)continue;
if(j>1)sum+=j;
if(n/j!=j)sum+=n/j;
}
return sum;
}
static long H(long m){
// 今回は m < 1e9 程度なので、愚直に(O(√m)で)計算しても間に合いそう。
long ret=0;
int N=m.ToString().Length;
for(int i=1;i<=N;i++){
if(i%2==1){
// abcdcba の形なので、abcd部分を 1000~9999まで回す
long strt=(long)Math.Pow(10,i/2);
long end=(long)Math.Pow(10,i/2+1);
for(long j=strt;j<end;j++){
long num1=j*(long)Math.Pow(10,i/2);
long num2=Reverse(j/10);
long num=num1+num2;
if(num<=m){
ret+=num;
}else{
break;
}
}
}else{
// abcddcba の形なので、abcd部分を 1000~9999まで回す
long strt=(long)Math.Pow(10,i/2-1);
long end=(long)Math.Pow(10,i/2);
for(long j=strt;j<end;j++){
long num1=j*(long)Math.Pow(10,i/2);
long num2=Reverse(j);
long num=num1+num2;
if(num<=m){
ret+=num;
}else{
break;
}
}
}
}
return ret;
}
static long Reverse(long x){
long ret=0;
while(x>0){
ret*=10;
ret+=x%10;
x/=10;
}
return ret;
}
static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment