737

qwwjh

eternalnian

1天前
#include<bits/stdc++.h>
using namespace std;
bool prime(int x)
{
for(int i=2;i<=x/i;i++)
if(x%i==0)return 0;
return 1;
}
int main()
{
int n,i;
while(cin>>n){
bool ok=0;
for(int i=2;i<=n-1;i++)
if(prime(i)&&i%10==1)cout<<i<<' ',ok=1;
if(ok==0)cout<<-1;
cout<<'\n';
}
}


1天前
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
string s;
while(cin >> s, s != "0"){
int ans = 0;
for(int i = 0; i < s.size(); i++)
ans += s[i] - '0';
ans %= 9;
if(ans) printf("%d\n", ans);
else printf("9\n"); //如果是0特判，结果其实是9
}
return 0;
}


1天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int n;
bool f=false;

int main()
{
while(cin>>n)
{
f=false;
for(int k=2;k<=n;k++)
{
if(n%(k*k)==0)
{
f=true;
}
}
if(f) puts("Yes");
else puts("No");
}
return 0;
}


1天前
class MyCircularDeque {
public:
vector<int> a;
int pos=0,size=0;
MyCircularDeque(int k) {
size=k;
}

bool insertFront(int value) {
if(isFull()) return false;
a.insert(a.begin(),value);
pos++;
return true;
}

bool insertLast(int value) {
if(isFull()) return false;
a.push_back(value);
pos++;
return true;
}

bool deleteFront() {
if(isEmpty()) return false;
a.erase(a.begin());
pos--;
return true;
}

bool deleteLast() {
if(isEmpty()) return false;
a.pop_back();
pos--;
return true;
}

int getFront() {
if(isEmpty()) return -1;
return a.front();
}

int getRear() {
if(isEmpty()) return -1;
return a.back();
}

bool isEmpty() {
if(!pos) return true;
return false;
}

bool isFull() {
if(pos==size) return true;
return false;
}
};

/**
* Your MyCircularDeque object will be instantiated and called as such:
* MyCircularDeque* obj = new MyCircularDeque(k);
* bool param_1 = obj->insertFront(value);
* bool param_2 = obj->insertLast(value);
* bool param_3 = obj->deleteFront();
* bool param_4 = obj->deleteLast();
* int param_5 = obj->getFront();
* int param_6 = obj->getRear();
* bool param_7 = obj->isEmpty();
* bool param_8 = obj->isFull();
*/


1天前
#include <bits/stdc++.h>
using namespace std;

const int N = 4e5 + 5;
int t, n, y;

int en, first[N];
struct edge {
int e, d, next;
}ed[N];

void add_edge(int s, int e, int d) {
en++;
ed[en].e = e, ed[en].d = d;
ed[en].next = first[s];
first[s] = en;
}

int ans;
void dfs(int x, int val) {
ans++;
for (int p = first[x]; p; p = ed[p].next) {
if (ed[p].d >= val) dfs(ed[p].e, val);
//  只有当前的边权大于等于val值才可以dfs，因为小于val值的边已经删掉了
}
}

bool check(int x) {
ans = 0;
dfs(0, x);
if (ans <= y) return 1;  // 1表示满足
else return 0; // 0表示不满足
}

int main() {
cin >> t;
while (t--) {
en = 0;
memset(first, 0, sizeof first);
cin >> n >> y;
for (int i = 1; i <= n - 1; i++) {
int u, v, w;
cin >> u >> v >> w;
if (u > v) swap(u, v);   // 已更改！如果u>v swap
add_edge(u, v, w);  // 存图
}
int l = 0, r = 1e7;  // 注意，二分边界必须要1e7!!
while (l < r) {  // 二分
int mid = l + r >> 1;
if (check(mid)) r = mid;  // 满足条件
else l = mid + 1;   // 不满足
}
cout << l << endl;
}
}


1天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int n;

int main()
{
while (cin >> n)
{
if (n % 4 == 3 || n % 4 == 1) cout << 0 << endl;
else cout << (n % 4 == 0 ? n / 4 - 1 : n / 4) << endl;
}
return 0;
}


1天前
#include<iostream>
#include<vector>

using namespace std;

vector<int> add(vector<int> &A,vector<int> &B)
{
vector<int> C;
int t=0;
for(int i=0;i<A.size()||i<B.size();i++)
{
if(i<A.size()) t+=A[i];
if(i<B.size()) t+=B[i];
C.push_back(t%10);
t/=10;
}
if(t) C.push_back(1);
return C;
}

int main()
{
string a,b;
while(cin>>a>>b)
{
vector<int> A,B;
for(int i=a.size()-1;i>=0;i--) A.push_back(a[i]-'0');
for(int i=b.size()-1;i>=0;i--) B.push_back(b[i]-'0');
auto C=add(A,B);
for(int i=C.size()-1;i>=0;i--) printf("%d",C[i]);
cout<<endl;
}
return 0;
}


2天前
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 300010;

int n, a[N];

int main()
{
scanf("%d", &n);

for(int i = 1; i <= n; i ++) scanf("%d", &a[i]);

unordered_map<int, int> h[2]; //h[0]是下标为偶数的哈希表,h[1]是下标为奇数的哈希表

int s = 0;  //异或前缀和
ll res = 0; //记录答案

h[0][s] ++;

for(int i = 1; i <= n; i ++) //枚举
{
s ^= a[i];  //异或前缀和s[i]

res += h[i % 2][s];  //将之前的异或前缀和为s的数目加入答案
h[i % 2][s] ++;     //将异或前缀和为s的数目加1
}

cout << res << endl;

return 0;
}


3天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int x;

int main()
{
while(cin>>hex>>x)
{
cout<<x<<endl;
}
return 0;
}


3天前
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

vector<string> ans;

int main()
{
string s;
while(cin>>s)
{
ans.push_back(s);
}
int n=ans.size();
for(int i=0;i<n-1;i++)
{
cout<<ans[i].size()<<' ';
}
cout<<ans[n-1].size()-1;
return 0;
}