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 a x2 +b⋅x+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;
}