题目链接:http://codeforces.com/contest/592/problem/B

B. The Monster and the Squirrel
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.

Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then starting from the vertex 1she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2, 3, ..., n (in this particular order). And then she puts a walnut in each region inside the polygon.

Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.

Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?

Input

The first and only line of the input contains a single integer n (3 ≤ n ≤ 54321) - the number of vertices of the regular polygon drawn by Ari.

Output

Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.

Examples
input
5
output
9
input
3
output
1
Note

One of the possible solutions for the first sample is shown on the picture above.

找规律。

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
cout<<(n-)*(n-)<<endl;
}

─────────────────────────────────────────────────────────────────────────────────────────────

题目链接:http://codeforces.com/contest/592/problem/C

C. The Big Race
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of Lmeters today.

Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.

While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).

Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.

Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?

Input

The first line of the input contains three integers tw and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.

Output

Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.

The fraction  (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both pand q are divisible by d.

Examples
input
10 3 2
output
3/10
input
7 1 2
output
3/7
Note

In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.

题意:

两个人跑步比赛,一个人一步只能走w米,一个人一步只能走b米;

终点位置可以在整数1~t里面随便选择一个;

终点之后都是陷阱,两个人比赛但两个人都不想死,所以不能越过终点,在这种情况下,谁走的远,就算谁赢;

然后问你选择平局的概率是多少。

题解:

算算样例,可以看出所有最小公倍数情况的终点都能产生平局;

我们设tail=min(w,b)-1,可以看出,1~tail位置的终点也产生平局,每个最小公倍数终点后面tail个位置也能产生平局;

那么我们就围绕这个进行计算,可以按照1~t里有多少个lcm(w,b)整数倍终点进行分类考虑;

不过有一个错误点就是lcm(w,b)超过unsigned long long范围的情况,

这样一来,因为t的范围限制,lcm(w,b)必然大于t了,只需要在前面特判一下lcm(w,b)>t的情况即可,

具体怎么特判,lcm(w,b) = (w*b) / gcd(w,b) > t,两边取对数进行比较即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long llu;
inline llu gcd(llu m,llu n){return n?gcd(n,m%n):m;}
llu lcm(llu m,llu n){return m/gcd(m,n)*n;}
void output(llu p,llu q)
{
llu pq_gcd=gcd(p,q);
cout<<p/pq_gcd<<"/"<<q/pq_gcd<<endl;
}
bool check(llu t,llu w,llu b)
{
return log(w*1.0)+log(b*1.0)-log(gcd(w,b)*1.0)>log(t*1.0);
}
int main()
{
llu t,w,b;
cin>>t>>w>>b; llu tail=min(w,b)-;//tail>=0 if(check(t,w,b))//判断lcm(w,b)>t?
{
output(min(tail,t),t);
return ;
} llu wb_lcm=lcm(w,b);
llu cnt=t/wb_lcm;
if(cnt==)
{
if(t<=tail)
{
cout<<"1/1"<<endl;
return ;
}
else
{
output(tail,t);
return ;
}
}
else if(cnt==)
{
llu ed=min(t%wb_lcm,tail)+;
output(tail+ed,t);
return ;
}
else
{
llu ed=min(t%wb_lcm,tail)+;
output(tail+(cnt-)*(tail+)+ed,t);
return ;
}
}

codeforces 592B/C的更多相关文章

  1. CodeForces 592B

    题目链接: http://codeforces.com/problemset/problem/592/B 这个题目没啥说的,画图找规律吧,哈哈哈 程序代码: #include <cstdio&g ...

  2. codeforces 592B The Monster and the Squirrel

    题目链接:http://codeforces.com/contest/592/problem/B 题目分类:数学,找规律 题目分析:重要的是画图找规律   代码: #include<bits/s ...

  3. Codeforces Round #328(Div2)

    CodeForces 592A 题意:在8*8棋盘里,有黑白棋,F1选手(W棋往上-->最后至目标点:第1行)先走,F2选手(B棋往下-->最后至目标点:第8行)其次.棋子数不一定相等,F ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. Android测试跑单个包脚本文件

    脚本: adb shell monkey -p 应用包名 --throttle 随机事件间隔 -v -v -v -s 1 --ignore-security-exceptions --kill-pro ...

  2. CentOS-6.4 安装 PHP Memcached 扩展

    1.获取安装文件包 [root@phpdragon home]# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmem ...

  3. ajax简单手写了一个猜拳游戏

    使用ajax简单写一个猜拳游戏 HTML代码 <!DOCTYPE HTML> <html lang="en-US"> <head> <me ...

  4. AddChild

    using UnityEngine; using UnityEngine; using UnityEditor; using System.Collections; public class AddC ...

  5. MQ java 基础编程(一)

    本文转自:http://www.blogjava.net/i369/articles/88035.html 编写人:邬文俊 编写时间 : 2006-2-16 联系邮件 : wenjunwu430@gm ...

  6. codeforces水题100道 第十题 Codeforces Round #277 (Div. 2) A. Calculating Function (math)

    题目链接:www.codeforces.com/problemset/problem/486/A题意:求表达式f(n)的值.(f(n)的表述见题目)C++代码: #include <iostre ...

  7. Lua中的table构造式(table constructor)

    最简单的构造式就是一个空构造式{},用于创建一个空table. 构造式还可以用于初始化数组.例如,以下语句:days = {"Sunday", "Monday" ...

  8. Python进阶 学习笔记(一)

    (笔记范围:第一章 课程介绍:第二章 函数式编程:第三章 模块) Python支持的函数式编程 不是纯函数式编程:允许有变量 支持高阶函数:函数也可以作为变量传入 支持闭包:有了闭包就能返回函数 有限 ...

  9. 《转载》Tomcat内存设置详解

    原文地址:Java内存溢出详解 一.常见的Java内存溢出有以下三种: 1. java.lang.OutOfMemoryError: Java heap space ----JVM Heap(堆)溢出 ...

  10. sklearn包学习

    1首先是sklearn的官网:http://scikit-learn.org/stable/ 在官网网址上可以看到很多的demo,下边这张是一张非常有用的流程图,在这个流程图中,可以根据数据集的特征, ...