zoukankan      html  css  js  c++  java
  • 高精度乘法

    Description

    Think about a plane: 

    ● One straight line can divide a plane into two regions. 
    ● Two lines can divide a plane into at most four regions. 
    ● Three lines can divide a plane into at most seven regions. 
    ● And so on... 

    Now we have some figure constructed with two parallel rays in the same direction, joined by two straight segments. It looks like a character “M”. You are given N such “M”s. What is the maximum number of regions that these “M”s can divide a plane ? 

     

    Input

    The first line of the input is T (1 ≤ T ≤ 100000), which stands for the number of test cases you need to solve. 

    Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 10 12)
     

    Output

    For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then an integer that is the maximum number of regions N the “M” figures can divide.
     

    Sample Input

    2 1 2
     

    Sample Output

    Case #1: 2
    Case #2: 19
     
     
    解题思路:在直线划分平面中f(n)=f(n-1)+(n-1)+1;
    推测"M"划分平面中,一次是4条线划分,故f(n)=f(n-1)+4*(n-1)+1;
    整理得f(n)=8*n*n-7*n+1;
    n取值范围为10^12次方,故使用高精度乘法。
     
     
     
     
     
     
     
     
  • 相关阅读:
    更好地限制一个UITextField的输入长度
    训练集(train set) 验证集(validation set) 测试集(test set)
    主流机器学习[xgb, lgb, Keras, LR]
    python pandas (ix & iloc &loc) 的区别
    机器学习:数据预处理之独热编码(One-Hot)
    SPARK第一天
    Spark简介
    scatter
    协方差和相关关系
    SQL存储过程
  • 原文地址:https://www.cnblogs.com/chen9510/p/4866479.html
Copyright © 2011-2022 走看看