#include<bits/stdc++.h> using namespace std; int main() { int x,xx,xxx; cin>>x>>xx>>xxx; int result = (max(x,max(xx,xxx))) -( min(x,min(xx,xxx))); cout<<result<<endl; return 0; }
Tuesday, October 4, 2016
CF 723A
Sunday, October 2, 2016
Link List - Insertion and Print inserted data
#include<bits/stdc++.h> using namespace std; struct node { int data; int key; struct node *next; }; struct node *head = NULL; struct node *current = NULL; void InsertFirst(int key,int data) { struct node *link = (struct node*) malloc(sizeof(struct node)); link->key=key; link->data=data; link->next = head; head = link; } void printList() { struct node *ptr=head; while(ptr != NULL) { cout<<"("<<ptr->key<<","<<ptr->data<<")"; ptr=ptr->next; } cout<<endl; } int main() { int data,key; for(int i=0; i<4; i++) { cin>>data>>key; InsertFirst(data,key); } printList(); return 0; }
Saturday, September 3, 2016
UVa - 10892 LCM Cardinality
#include<bits/stdc++.h> #include<vector> #include<cmath> #define ll long long using namespace std; ll gcd(ll a,ll b) { return b? gcd(b,a%b):a; } ll lcm(ll a,ll b) { return (a*b/gcd(a,b)); } int main() { ll n,sq,m,count; while(cin>>n) { vector<ll>fact; if(n==0) break; sq = sqrt(n); for(ll i=1; i<=sq; i++) { if(n%i==0) { fact.push_back(i); fact.push_back(n/i); } } if(sq*sq==n) fact.pop_back(); count=0; ll vsize = fact.size(); for(ll i=0; i<vsize; i++) { for(ll j=i; j<vsize; j++) { if(lcm(fact[i],fact[j])==n) count++; } } cout<<n<<" "<<count<<endl; } }
Subscribe to:
Posts (Atom)