zoukankan      html  css  js  c++  java
  • 2012 #5 History repeat itself

    History repeat itself
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    Tom took the Discrete Mathematics course in the 2011,but his bad attendance angered Professor Lee who is in charge of the course. Therefore, Professor Lee decided to let Tom face a hard probability problem, and announced that if he fail to slove the problem there would be no way for Tom to pass the final exam. 
    As a result , Tom passed. 
    History repeat itself. You, the bad boy, also angered the Professor Lee when September Ends. You have to faced the problem too. 
    The problem comes that You must find the N-th positive non-square number M and printed it. And that's for normal bad student, such as Tom. But the real bad student has to calculate the formula below. 

    So, that you can really understand WHAT A BAD STUDENT YOU ARE!!
     

    Input

    There is a number (T)in the first line , tell you the number of test cases below. For the next T lines, there is just one number on the each line which tell you the N of the case. 
    To simplified the problem , The N will be within 2 31 and more then 0.
     

    Output

    For each test case, print the N-th non square number and the result of the formula.
     

    Sample Input

    4 1 3 6 10
     

    Sample Output

    2 2 5 7 8 13 13 28
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 long long a[70007],b[70007];
     5 int main()
     6 {
     7     int T;
     8     long long i,j,k;
     9     long long  n;
    10     scanf("%d",&T);
    11     a[0]=0;
    12     for(i=1;i<=70000;i++)
    13     {
    14         a[i]=a[i-1]+i*(i*2+1);
    15     }
    16     for(i=1;i<=70000;i++)
    17     {
    18         b[i]=i*i-i+1;
    19     }
    20     while(T--)
    21     {
    22         scanf("%I64d",&n);
    23         for(i=1;i<=70000;i++)
    24         {
    25             if(n<b[i])
    26             {
    27                 i--;
    28                 break;
    29             }
    30         }
    31         long long x=(n-b[i]+1)+i*i,y=a[i-1]+i*(n-b[i]+2);
    32         printf("%I64d %I64d
    ",x,y);
    33     }
    34     return 0;
    35 }
    View Code
     
  • 相关阅读:
    【背包九讲专题】完全背包
    【指数降幂】费马小定理降幂&欧拉降幂
    【背包九讲专题】01背包
    2016ACM-ICPC亚洲区域赛(大连)
    Codeforces Round #697 (Div. 3)题解报告(A-G)
    pywifi 网卡反复断开连接
    webdriver xpath frame alert window
    windows pexpect ssh
    python3 串口读写 pyserial
    python3 unittest addTest 与addtests
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771451.html
Copyright © 2011-2022 走看看