A,Sum of 2050
Source: https://codeforces.com/problemset/problem/1517/A
Label: [thinking] [simple]
Difficulty: ★☆☆☆
Topic description
If a number is 2050 * 10K (k > = 1), it is called 2050 number. Enter a number n to judge whether it is composed of one or more 2050 numbers. If yes, how many 2050 numbers does the output consist of at least? Otherwise, output - 1.
Input
T: Number of test groups.
Input an n for each group of tests: the number to be judged (1 < = n < = 1018).
Output
Such as title
Sample Input
6 205 2050 4100 20500 22550 25308639900
Sample Output
-1 1 2 1 2 36
More Info
In the third case, 4100=2050+2050. In the fifth case, 22550=20500+2050.
Topic idea
First, judge whether n is a multiple of 2050, not directly output - 1; If yes, define p as n/2050, and calculate the sum of the bits of p as the answer.
Code (with notes)
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; int t; int main() { ios::sync_with_stdio(false); cin>>t; while(t--){ ll x,ans=0; cin>>x; if(x%2050==0){ ll p=x/2050; while(p){//Take each digit ans+=p%10; p/=10; } cout<<ans<<endl; } else cout<<-1<<endl; } return 0; }
C,Perfectly Imperfect Array
Source: https://codeforces.com/problemset/problem/1514/A
Label: [mathematics] [thinking]
Difficulty: ★☆☆☆
Topic description
Given a sequence of a with n elements, judge whether there is such a sub sequence of a: the product of all elements in the sub sequence is not a complete square. If YES, output YES; otherwise, output NO. (the sub sequence of a is defined as the sequence formed by deleting 0 or more elements)
Input
T (1 < = T < = 100): number of test groups. For each group:
n: number of sequences.
n number: a1,a2... an.
Output
If there is any non empty subsequence sequence whose product is not a complete square, output "YES", otherwise output "NO"
Sample Input
2 3 1 5 4 2 100 10000
Sample Output
YES NO
More Info
In the first example, the product of the whole array (20) isn't a perfect square. In the second example, all subsequences have a perfect square product.
Topic idea
At first, I thought it was complicated. Although n was very small, simulation was not necessary. In fact, if you think about it carefully, you will find that NO can be output only if each number in the a series is a complete square number, otherwise you can only output YES.
Code (with notes)
#include <iostream> #include <algorithm> #include <cmath> using namespace std; int t,n; double a[105]; int main() { ios::sync_with_stdio(false); cin>>t; while(t--){ int flag=0; cin>>n; memset(a,0,sizeof(a)); for(int i=1;i<=n;i++){ cin>>a[i]; if(sqrt(a[i])-(int)(sqrt(a[i]))!=0)//Not a perfect square flag=1; } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
D,AND 0, Sum Big#
Source: https://codeforces.com/problemset/problem/1514/B
Label: [bit operation] [number theory]
Difficulty: ★★☆☆☆
Topic description
Given two numbers n and k, calculate the number of sequences with length n and the following conditions:
1. All elements belong to [0,2k-1];
2. The bitwise sum operation result of all elements is 0;
3. Elements and as large as possible;
The answer may be very big. Take the model of 1e9+7.
Input
T: Number of test groups (T < = 10).
Input one n, k(1 ≤ n ≤ 105, 1 ≤ k ≤ 20) for each test group;
Output
Output the result of 1e9+7 modulo of the answer
Sample Input
2 2 2 100000 20
Sample Output
4 226732710
More Info
In the first example, the 4 arrays are: [3,0], [0,3], [1,2], [2,1].
Topic idea
When I did it, I thought there must be a calculation formula. Unfortunately, I was too stupid to think of it. After reading the problem solution, it turned out to be a fast power. It's a pity that I can try it out a few more times. I don't know why it is nk%mod.
Code (with notes)
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int mod=1e9+7; ll n,t,k; ll ksm(ll a,ll b) //Counting { ll res=1; while(b){ if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res%mod; } int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>t; while(t--){ cin>>n>>k; cout<<ksm(n,k)<<endl; } return 0; }
E,Product 1 Modulo N#
Source: https://codeforces.com/problemset/problem/1514/C
Tags: [mathematics] [greed] [thinking]
Difficulty: ★★☆☆
Topic description
Given a number n, find the longest subsequence of [0,1,2,..., n-1], so that the product remainder n of all numbers of 1 in the subsequence is equal to 1. (b is a subsequence of a, that is, b can be obtained by deleting several elements from a, possibly all, and an empty sequence is specified to represent 1.)
Input
n (2≤n≤105).
Output
First, output a number representing the length of the longest sequence that satisfies the answer.
Then the next line outputs the sequence (any one) that meets the conditions.
Sample Input_1
5
Sample Output_1
3 1 2 3
Sample Input_2
8
Sample Output_2
4 1 3 5 7
Topic idea
If the maximum common divisor of and N is 1 (i.e. coprime), the multiplication result must also be coprime with N. cycle from 1 to N and mark them all; Select a number P as the remainder of the product of these numbers and N; If P= 1, then vis[p]=0, discard p; The answer is marked in the front. Because if p%n is not 1, removing P is equivalent to multiplying all multiplication results not by P but by 1, and the corresponding result of% n will become 1. (as for why this is the longest, I don't understand - | - |)
Code (with notes)
#include <bits/stdc++.h> using namespace std; bool vis[100005]; int main() { int n; long long p=1; scanf("%d",&n); for(int i=1;i<n;i++){ if(__gcd(n,i)==1){//Coprime with n vis[i]=1; p=(p*i)%n; } } if(p!=1) vis[p]=0;//Abandon p cout<<count(vis+1,vis+1+n,1)<<endl; for(int i=1;i<n;i++){ if(vis[i]) cout<<i<<' '; } return 0; }