zoukankan      html  css  js  c++  java
  • Codeforces Round #636 A. Candies(水)

    Recently Vova found nn candy wrappers. He remembers that he bought xx candies during the first day, 2x2x candies during the second day, 4x4x candies during the third day, … , 2k1x2k−1x candies during the kk -th day. But there is an issue: Vova remembers neither xx nor kk but he is sure that xx and kk are positive integers and k>1k>1 .

    Vova will be satisfied if you tell him any positive integer xx so there is an integer k>1k>1 that x+2x+4x++2k1x=nx+2x+4x+⋯+2k−1x=n . It is guaranteed that at least one solution exists. Note that k>1k>1 .

    You have to answer tt independent test cases.

    Input

    The first line of the input contains one integer tt (1t1041≤t≤104 ) — the number of test cases. Then tt test cases follow.

    The only line of the test case contains one integer nn (3n1093≤n≤109 ) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer xx and integer k>1k>1 that x+2x+4x++2k1x=nx+2x+4x+⋯+2k−1x=n .

    Output

    Print one integer — any positive integer value of xx so there is an integer k>1k>1 that x+2x+4x++2k1x=nx+2x+4x+⋯+2k−1x=n .

    Example
    Input
    Copy
    7
    3
    6
    7
    21
    28
    999999999
    999999984
    
    Output
    Copy
    1
    2
    1
    7
    4
    333333333
    333333328
    高中题。。
    #include <bits/stdc++.h>
    using namespace std;
    int fpow(int a,int b)
    {
        int ans=1;
        for(;b;b>>=1)
        {
            if(b&1)ans*=a;
            a*=a;
        } 
        return ans;
    } 
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int n,k,i;
            cin>>n;
            for(k=2;;k++)
            {
                if(n%(fpow(2,k)-1)==0)
                 {
                     cout<<n/(fpow(2,k)-1)<<endl;
                     break;
                }
            }
        }
        return 0;
    }


  • 相关阅读:
    POJ 1988 Cube Stacking(带权并查集)
    POJ 1414 Life Line(搜索)
    POJ 3468 A Simple Problem with Integers (线段树多点更新模板)
    二叉树前序遍历+中序遍历->后序遍历
    POJ 1061 青蛙的约会(扩展欧几里得)
    XDOJ 1020 ACMer去刷题吧(基础dp)
    POJ 2823 Sliding Window (线段树区间查询)
    线段树学习(一)
    UVA 294 Divisors( 因子分解)
    YYN图论学习路线(推荐)
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12749849.html
Copyright © 2011-2022 走看看