DIY练习赛第一场

A题:

A - Cifera
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Appoint description: 

Description

When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.

Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2petricium la petricium la petricium stands for k3 and so on. All numbers of this form are calledpetriciumus cifera, and the number's importance is the number of articles la in its title.

Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.

Input

The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).

Output

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.

Sample Input

Input
5
25
Output
YES
1
Input
3
8
Output
NO


解题思路:

这好像是CF中div2的水题,,但是卡了3次才过,归其原因很简单,,第一个爆了int,第二个要注意阶乘的写法。

代码:

# include<cstdio>
# include<iostream>

using namespace std;

int k,l;

long long my_power( int n,int len )
{
    long long temp = 1;
    for ( int i = 1;i <= len;i++ )
    {
        temp = temp*n;
    }
    return temp;
}

void work()
{
    if ( k==l )
    {
        cout<<"YES"<<endl;
        cout<<"0"<<endl;
        return;
    }
    int t = 1;
    int flag = 0;
    while ( 1 )
    {
        if ( l==my_power(k,t+1) )
        {
            flag = 1;
            break;
        }
        else if ( l < my_power(k,t+1) )
        {
            break;
        }
        else
        {
            t++;
        }
    }
    if ( flag )
    {
        cout<<"YES"<<endl;
        cout<<t<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}

int main(void)
{
    while ( cin>>k>>l )
    {
        work();
    }


    return 0;
}

B题:

解题思路:

也是CFdiv2的B题,,几何题,题目说的是,任意画一条折线,这条折线必须要沿着格子的边,问能不能使得这条折线不经过题目中制定的那个格子的边。

其实,如果一个一个枚举的话,肯定有太多的情况需要讨论,我们就采取最为朴素的方法把,先从三角形想起来,我们知道,如果把一个三角形分成面积

相等的两部分,那么这条线一定要经过三角形三心中的任意一个,,,那么类比到四边形也就是一样的了,只要这条折线没有经过正方形中心的周围4个正

方形的话,那么我们就可以找到符合题目要求的这条折线了,只需要枚举这个点周围的4个正方形就OK了~

代码:

# include<cstdio>
# include<iostream>

using namespace std;

int main(void)
{
    int n;
    int x,y;
    while ( cin>>n>>x>>y )
    {
        if ( (x==n/2||x==n/2+1)&&(y==n/2||y==n/2+1) )
        {
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"YES"<<endl;
        }
    }


    return 0;
}


C题:

解题思路:

没想到什么快速的方法,既然让字典序最小,且满足都是lucky数字,那么就用贪心的思想,只要枚举出以abcd为周期的字符串就可以了,每次新增加一个字符的话,就补到abcd的后面,依次枚举出所有的情况就好了。


代码:

# include<cstdio>
# include<iostream>

using namespace std;

char s[] = {'a','b','c'};

int main(void)
{
    int n;
    while ( cin>>n )
    {
        int t;
        int len1 = n/4;
        int len2 = n%4;
        if ( len1 == 0 )
        {
            for ( int i = 0;i < n;i++ )
            {
                cout<<s[i];
            }
            cout<<endl;
        }
        else
        {
        for ( int i = 0;i < len1;i++ )
        {
            cout<<"abcd";
        }
        if ( len2 == 0 )
            cout<<endl;
            else if ( len2 == 1 )
                cout<<"a"<<endl;
            else if ( len2 == 2 )
                cout<<"ab"<<endl;
            else if ( len2 == 3 )
                cout<<"abc"<<endl;

        }

    }


    return 0;
}



D题:



E题:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值