The 3rd Shanxi Programming Contest: A Big Water Problem

The 3rd Shanxi Province Programming Contest

A big problem
Time limit: C/C++ 2000ms; Java 4000ms Memory limit: 65535K

Problem Description

    Dr. Pan作为上兰帝国ACM的总负责人,对队员的队员的训练也是日常关心,他要求每周要有一位队员出一道题目。不知过了多少年,终于轮到Shiyiliang出题了,他费尽脑汁,终于出了一道大水题
    给定一个偶数n,n的取值范围为[-1e18,1e18],要求一对整数x,y满足以下条件:
 1.x*y==n
 2.x与n必须同号,即如果n>0则x>0,n<0则x<0
 3.x必须为偶数,y必须为奇数
 4.y的取值范围为(-1e18,1e18)
 5.使x的值尽可能小的情况下,y的值尽可能大
 为了减轻队员的工作量,Dr. pan决定只要求输出y即可.
 输入描述
 第一行一个T(T<=100000)代表样例数。
 接下来T行,每行一个数字代表题目中的n(-1e18<=n<=1e18,保证n为偶数)。
 输出描述
 输出T行。
 每行一个数字代表题目中的y,该数字必须为奇数。
 样例输入
 1
 12
 样例输出
 3

This question has never been dealt with at that time. When n==0, y should be the largest odd number at this time! ! ! ! ! But I didn't expect that one y can't take any value all the time! ! ! ! At the end, the big guy said it, it's just emmmmmmmmmmm, I'm too naive.
This is the code that was later modified. It has not been submitted yet, but it should be no problem to change the pit.

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll ans=1e18;
int main()
{
      int T;
      ll n;
      scanf("%d",&T);
      while(T--)
      {
         scanf("%lld",&n);
         if(n>0)
         {
           while(true)
          {
            if((n/2)&1)
            {
             printf("%lld\n",(n/2));
             break ;
            }
            else
            n=n/2; 
          }
         }
         else
         {
             //if(n==0)
             //printf("\n");
             if(n==0)
             printf("%lld\n",ans-1); 
             else
             printf("1\n");
             continue;      
         }
      }
    //system("pause");
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325337989&siteId=291194637