山东省第八届ACM省赛(G I F)

G - sum of power

Description

Input

Input contains two integers n,m(1≤n≤1000,0≤m≤10).

Output

Output the answer in a single line.

Sample Input

10 0

Sample Output

10

注意是1e9+7不是1e8+7

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <string>
#include <stack>
#include <deque>
using namespace std;
//#define MAX 0x3f3f3f
const int MAX=1e9+7;
typedef long long ll;
int fast_pow(ll a,ll b)
{
    ll ans=1;
    a%=MAX;
    while(b)
    {
        if(b&1)
            ans=a*ans%MAX;
        a=a*a%MAX;
        b>>=1;
    }
    return ans%MAX;
}
int main()
{
    ll n,m,i,ans=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        ans+=fast_pow(i,m);
    cout<<ans%MAX<<endl;
}

I - Parity check

Description

Input

Multiple test cases. Each test case is an integer n(0≤n≤101000 101000 ) in a single line.

Output

For each test case, output the answer of f(n)mod2.

Sample Input

2

Sample Output

1

数太大了,找规律做,f(0)=0,f(1)=1,f(2)%2=1,f(3)%2=2%2=0,f(4)%2=3%2=1,f(5)=5%2=1,f(6)=8%2=0……

规律是011011……

还有要用字符串存。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <string>
#include <stack>
#include <deque>
using namespace std;
//#define MAX 0x3f3f3f
const int MAX=1e9+7;
typedef long long ll;
int main()
{
    string a;
    ll i,sum=0,n;
    a.clear();
    while(cin>>a)
    {
        sum=0;
        n=a.size();
        for(i=0; i<n; i++)
        {
            sum+=a[i]-'0';
        }
        if(sum%3==0)
            cout<<"0"<<endl;
        else
            cout<<"1"<<endl;
        a.clear();
    }

}

F - quadratic equation

Description

With given integers a,b,c, you are asked to judge whether the following statement is true: "For any x, if x2 +bx+c=0, then x is an integer."

Input

The first line contains only one integer T(1≤T≤2000), which indicates the number of test cases.
For each test case, there is only one line containing three integers a,b,c(−5≤a,b,c≤5).

Output

or each test case, output “YES” if the statement is true, or “NO” if not.

Sample Input

3
1 4 4
0 0 1
1 3 1

Sample Output

YES
YES
NO

题意:判断a*x*x+b*x+c=0是否有非整数解,有输出NO,没有YES。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <string>
#include <stack>
#include <deque>
using namespace std;
const int MAX=1e9+7;
typedef long long ll;
int main()
{
    ll t,a,b,c,m;
    cin>>t;
    while(t--)
    {
        cin>>a>>b>>c;
        if(a==0)
        {
            if(b==0)
            {
                if(c==0)
                {
                    cout<<"NO"<<endl;
                    continue;
                }
                else
                {
                    cout<<"YES"<<endl;
                    continue;
                }
            }
            else
            {
                if(c%b==0)
                {
                    cout<<"YES"<<endl;
                    continue;
                }
                else
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
        }
        else
        {
            m=b*b-4*a*c;
            if(m<0)
            {
                cout<<"YES"<<endl;
                continue;
            }
            else
            {
                double xx=sqrt(m);
                if((-b+xx)/(2*a)-(int)(-b+xx)/(2*a)==0&&(-b-xx)/(2*a)-(int)(-b-xx)/(2*a)==0)
                {
                    cout<<"YES"<<endl;
                    continue;
                }
                else
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
        }
    }
    return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值